Geolocation on the electron js - node.js

How can I add the location of the ip address location in the logg file to the interface?
My view.js file
if(fs.existsSync("logg.txt")){
let data = fs.readFileSync("log.txt").split("\n")
data.forEach((log,index)=>{
const rawLog = log?.split(" ")
let ip = rawLog[0];
I try this website but I don't show on the app interface.
https://www.abstractapi.com/guides/node-js-get-ip-address

Related

instead of uploading doc i need to choose only path in nodejs

I have an application which needs the full path of the file when clicking on choose file button. Now I want to get the full path of that file. For e.g. D:\MyNodeApp\project\text.doc
How do I get the file location in node.js?
If you want client file location you can get this in client side using javascript
document.getElementById("file-upload").onchange = function(event) {
var reader = new FileReader();
reader.readAsDataURL(event.srcElement.files[0]);
var me = this;
reader.onload = function () {
console.log(reader)
}
it's not possible because of security purpose.

Terraform - GCP - link an ip address to a load balancer linked to a cloud storage bucket

What I want:
I would like to have a static.example.com DNS records that link to a bucket in GCS containing my static images.
As I manage my DNS through Cloudflare, I think I need to use the fact that GCP can attribute me an anycast-IP , to link that IP to a GCP load balancer , that will be linked to bucket
What I currently have:
a bucket already created manually , named "static-images"
the load balancer linking to said bucket, created with
resource "google_compute_backend_bucket" "image_backend" {
name = "example-static-images"
bucket_name = "static-images"
enable_cdn = true
}
the routing to link to my bucket
resource "google_compute_url_map" "urlmap" {
name = "urlmap"
default_service = "${google_compute_backend_bucket.image_backend.self_link}"
host_rule {
hosts = ["static.example.com"]
path_matcher = "allpaths"
}
path_matcher {
name = "allpaths"
default_service = "${google_compute_backend_bucket.image_backend.self_link}"
path_rule {
paths = ["/static"]
service = "${google_compute_backend_bucket.image_backend.self_link}"
}
}
}
an ip created with:
resource "google_compute_global_address" "my_ip" {
name = "ip-for-static-example-com"
}
What I'm missing:
the terraform's equivalent to the "frontend configuration" when creating a load balancer from the web console
Looks like you're just missing a forwarding rule and target proxy.
The terraform docs on google_compute_global_forwarding_rule have a good example.
e.g.:
resource "google_compute_global_forwarding_rule" "default" {
name = "default-rule"
target = "${google_compute_target_http_proxy.default.self_link}"
port_range = 80 // or other e.g. for ssl
ip_address = "${google_compute_global_address.my_ip.address}"
}
resource "google_compute_target_http_proxy" "default" { // or https proxy
name = "default-proxy"
description = "an HTTP proxy"
url_map = "${google_compute_url_map.urlmap.self_link}"
}
hope this helps!

Azure Web App Bot - Access local resources

My Web App Bot should return images, based on the request. The images are located in the .csproj in a folder, with following configuration
The sourcecode to send the image to the user
var imgMessage = context.MakeMessage();
var attachment = new Attachment();
attachment.ContentUrl = $"{HttpContext.Current.Request.Url.Scheme}://{HttpContext.Current.Request.Url.Authority}/Resources/{InvocationName}/{InvocationNameExtension}.jpg";
attachment.ContentType = "image/jpg";
attachment.Name = "Image";
context.PostAsync(attachment.ContentUrl);
While it works locally, it doesn't work after it has been published to the Azure cloud. However, the path to the Azure cloud is something like: https://xxxx.azurewebsites.net/Resources/img/Cafeteria.jpg
The FTP upload did include the file
2>Adding file (xxxx\bin\Resources\img\Cafeteria.jpg).
The file is on the server, but it can't be accessed. How am I supposed to include an image, located in the .csproj? I don't want to refer to an external URL due independency.
Changed the Build Action to: "Embedded Resource".
string resourceFile = ResourceManager.FindResource(InvocationName, InvocationNameExtension);
string resourceFileExtension = ResourceManager.GetResourceExtension(resourceFile);
var attachment = new Attachment();
attachment.ContentUrl = BuildImageUrl(resourceFile, resourceFileExtension);
attachment.ContentType = $"image/{resourceFileExtension}";
private string ConvertToBase64(string resourceFile) => Convert.ToBase64String(ResourceManager.GetBytes(resourceFile));
private string BuildImageUrl(string resourceFile, string resourceFileExtension) => "data:image/" + resourceFileExtension + ";base64," + ConvertToBase64(resourceFile);
With this approach I send directly the content of the image via base64 to the user. Works like a charm

Get remote IP in Parse.com

There is a mechanism in node to get the remote IP by calling req.connection.remoteAddress.
I tried the below code to get the remote IP of the client but the result is undefined.
var ipAddr = req.headers["x-forwarded-for"];
if (ipAddr){
var list = ipAddr.split(",");
ipAddr = list[list.length-1];
} else {
ipAddr = req.connection.remoteAddress;
}
console.log("req.connection.remoteAddress:" + ipAddr);
Does anyone know if I can get the remoteIP in Parse.com cloud code?

Uncaught TypeError: Cannot call method 'connectNative' in Native Messaging App

I am working on native messaging app.I have created following files
1.C++ conole app
2.JS file
3. manifet file
I have created registry entry like this
Now I am getting error in the line port = chrome.runtime.connectNative(hostName);.I noticed chrome.runtime itself is undefined.let me know am I missing anything here.
Manifest.jason
function connect() {
//var m1 = chrome.runtime.getManifest();
var hostName = "NM1";
var t1 = chrome;
appendMessage("Connecting to native messaging host <b>" + hostName + "</b>")
port = chrome.runtime.connectNative(hostName);
port.onMessage.addListener(onNativeMessage);
port.onDisconnect.addListener(onDisconnected);
updateUiState();
}
main.js
function connect() {
//var m1 = chrome.runtime.getManifest();
var hostName = "NM1";
appendMessage("Connecting to native messaging host <b>" + hostName + "</b>")
port = chrome.runtime.connectNative(hostName);
port.onMessage.addListener(onNativeMessage);
port.onDisconnect.addListener(onDisconnected);
updateUiState();
}
You will probably get this error if you aren't running the javascript within your extension. The chrome runtime doesn't exist outside that, and if you are running the javascript via injection, the runtime doesn't exist there.
Furthermore, don't forget to include the nativeMessaging permission in the manifest.json.
"permissions": [
"nativeMessaging"
]

Resources