Web Application using Ember.js and the dynamic ip backend API - javascript

I'm playing more and more with Ember and I really like it.
It's new to me but guides are solid and everything.
I understand how to pin-point the API Server IP so Ember can use it, but I would like to make it more dynamic - The idea is that the API Server is on LAN network (or on dynamic IP WAN - but I don't want ddns for that)
The problem is that I currently have to type IP address then deploy and that version work with that one IP address. I would love to be able to type in IP address on first? and then use that ip as the endpoint for api server.
I'm more than sure this is somehow possible but I lack the examples out there.
I understand that there should be application/index.js route that would check some kind of 'store' to check if there is ip address with array that was saved locally in file?/cookie? and if there is one then somehow load that ip to the adapters/application.js host?

Use an initializer if you have to initialize something.

Related

API Requires Static IP Addresses but I use a CDN

I am looking to use a JSON API that requires that I enter a set of specific IP addresses to allow access to in order to obtain an API key. However, I use a web host that uses a CDN (It should also be noted that I cannot modify any server-side code), so I cannot get a static IP address for my website's server. Is there any way for me to get around this? Is there a way for me make the GET requests to the API through a server with a static IP address that will then relay the request response to the client?
You can setup an reverse proxy on a server with static IP for that (e.g use NGINX). You can easily find some examples on Google like this
The "server with a static IP address" you need is named a reverse-proxy server.
You can install such a server on any cloud Linux or Windows instance: just install Apache according to the following documentation: https://httpd.apache.org/docs/2.4/howto/reverse_proxy.html

How to send Client IP Address as AJAX request data

I'd like to grab a client IP address using javascript and send it over to my server using AJAX request. Any suggestions on how I can achieve this would be awesome. Some code example would be even better.
Thanks in advance!
Front-end Javascript by itself doesn't have access to anything that will tell it a user's IP address. See here:
How to get client's IP address using JavaScript?
However, like it says in that answer, there are APIs you can use to get the IP address.
More importantly, though, any server receiving your AJAX request will have automatic access to the IP address. So if you can set up code on the server you should be good to go, or at least will have a different question.
If you don't have control over the server, and instead are doing something like POSTing data to a webforms API, then using an API is your best bet.
Client-side JavaScript has no access to the network addresses. What you're specifically asking for isn't possible.
You can determine the closest routable address for the client server-side, but this could always be an upstream proxy or NAT router.

Meteor: How to get Ip address for custom tracking system

I am very confused about ip addresses and headers. So I'm sorry if my question seems simple.
I have gone through the answers listed here:
How to get the user IP address in Meteor server?
But I can't figure out how to make them work. For example, I am trying to use this:
Meteor.onConnection(function(conn) {
console.log(conn.clientAddress);
});
But nowhere can I find where to place it.
If I place it on the client side it says Meteor.onConnection is undefined. If I place it on the server nothing happens. I don't think you run it on meteor.startup.
Is there someone could give me a hand in explaining where to use this code? Specifically if anyone has built a custom tracking system, that would be great. Do you store ips into database? or how to record for tracking purposes?
Any hint will help! thanks
Place the code anywhere on the server. e.g. in server/main.js. There is no need to call it from within Meteor.startup.
Start the app.
Open your browser to the appropriate address (e.g. http://localhost:3000) - this will cause a web client to connect and run the code from (1).
Look at your shell output (the shell you used to start the app - not the browser console) and you should see your local IP address (127.0.0.1) printed.
This should work in production as well, however if your app is served behind a proxy (e.g. nginx) you will need to add the appropriate commands to pass the user's IP to your app. For nginx, see this post.

Get the outside IP of the server the webapp is hosted on

How can I get the global IP of the server?
I could do a http request to 'http://wtfismyip.com/json' and get the IP address.
Is there a way to get the IP (or dns) whitout doing an outside request?
I can't find anything on the 'process.env' or 'os' object.
I use nodejs with express and deploy to heroku.
Simple answer: No. You'll need some kind of outside source. That source could be as local as the router if you had access to it, but it's more work than it's worth. And if you're on a hosting solution that's out anyway.
I assume your reason for wanting to get this quickly is for speed optimization? If so then I recommend you not worry about it. It's such a small action it won't have any lasting impact.
Now that I think about it; you should already know your public IP! If it's a hosted solution it ought not to change so you can get it once and just hard-code it into your project. I have no experience with heroku though, so it's possible they use a dynamic IP.

Node.js - Getting the host IP address while on Amazon EC2

How can I get the IP address (elastic IP) of the current Node.js host/server on Amazon EC2?
Calling req.connection.address() is useless because EC2 uses an elastic IP. In fact, the IP that shows up using the ifconfig command is not the same as the IP which was used to access the server from outside (which is what I need). How can I get the elastic IP automatically?
From within the instance, you can query for metadata about the instance by sending requests to http://169.254.169.254.
More information can be found here: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html
You can use DescribeInstances in the API as per the documentation using the filter ip-address to get the public IP of your instance.
Reading about headers and about elastic IP's, I would suggest that headers['REMOTE_ADDR'] gives the address you're looking for (unless behind a load balancer).

Categories