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.
Related
I'm stumped. So I've written a nice little web app that gets all its data from a JSON that has one array in it. To bridge the AngularJS-parts and the data, I have this line in my services.js
.constant("baseURL","http://localhost:3000/")
This of course only works with me locally. But I haven't considered that I might have to get my web host to serve up the data.
Now, I'm a complete beginner at this. I've managed to code my app with moderate effort, having only started coding in January. So I'm completely out of my league here. I don't even know what I'm looking for. I mean, I have to replace the localhost:3000with something. But if I do http://domain.com/db.json that obviously doesn't work.
I've talked to Godaddy's tech support and they go "Nuh-uh, not helping" the second I show them this line of code. Because, to be honest, I don't even know what the address I'm looking for is called. Is it a URI?
I have a few questions regarding this and I turn to you, because - this story gets worse - there's a possible job on the line for me. Not a coding thing, but the data that is parsed from the JSON into the site.
What is the address I'm looking for called?
How do I get my hosting to serve up JSON data? I mean, I don't even know what I need to ask the tech support people here. Do I need a JSON server?
If they don't offer it, where could I get my JSON data served in a way that I can push more articles into the array and preferrably edit it, too?
Thank you so much!
EDIT #1
If it helps, here's the contents of my /webroot/personalfolder
You will need to change your localhost:8000 to your domain name. For example, if you bought www.foobar.com then your base URL would just become www.foobar.com On a rented web server (like GoDaddy Hosting) ports 80 and 443 are normally open so you wouldn't need to specify this. If you are self hosting, you will need to open these ports on your router and apply port forwarding rules to your PC.
When you host your published website, you will just put your JSON file in with your Website Source. For example your structure may look like this:
AngularAppFolder/index.html
js
csss
Just add another folder called db place your JSON file in there, and reference it in your Angular code, no need to worry, its just another file just like your HTML or CSS which makes up your website. Remember though that your JSON data will be publicly available here!
If your looking for an alternative way of getting your JSON data, you may want to look into creating a REST API. This uses a web server to dish out data depenant on the HTTP request you send to it. but that's a very big topic! Here is some reading into it if your feeling brave! Node.js REST API tutorial
Final note: if you are self-hosting this application (running it on your own computer or server) then you will need to change the DNS record for your domain name to the global IP address of the server! you shouldn't have to worry if your using the hosting offerings from a company such as GoDaddy however.
You need to change the baseURL value to whatever the URL on which the site is hosted. Something like http://<mysite>.com.
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.
I am trying to make a sign up activity on android and I am using a mysql database to store the data. On all the examples I have seen the http post goes to a ip address and then finds the php file. Can I just put the php file somewhere in the android app folder and access it from there, or do I have to find a host for it?
The php code, specially for tasks such as sign up, should never be placed on the client side or embedded with the front end application, but instead be placed on the server side hidden from the user for the sake of safety of your database/application. If you are only considering to put your php with your Android app together for the case you need to test it, and eventually doesn't have access to a server, you may then consider using Google App Engine, as it allows you to emulate a server locally without the need of a server. Here you find some info about Amazon's RDS.
You can put you php in the same directory you place your index.html file, i.e. in the root public directory of your domain. To load it to the Amazon, you can use the cPanel or the Filezilla or any other panel you wish among the options Amazon put available for their users.
In the case Amazon doesn't provide a place to put your php, as a suggestion, you can get a host that allows you to have a static ip accessing it thorough an easy to remember url address - for free. It is quite useful specially for making tests. Still if you decide at some point to have a personalized domain name registered, there are also some other good options to compare.
You dont need jQuery, when doing the POST request,PHP connects to the database get the data and return it to your app.
So to answer your question you should put the PHP in the same server where mysql runs.
So I'm getting into working with node.js and socket.io to make real-time web games, but I'm running into some obstacles.
I've already figured out how to install node.js and socket.io on my computer, and I can run basic servers and open them through http://localhost:8888/.
But now what I don't understand, and there doesn't seem to be anything on the web that explains this, is how to get this onto a website. Obviously, someone else on the internet that enters that same URL isn't going to see the same thing as what's on my screen. How do I get this onto a webpage so that anyone that visits that URL accesses the server?
I tried opening the port and then using http://<my external IP>:8888 but that doesn't work. Some sources seem to say that I need to install something on the website, but I installed node.js on my computer through command prompt, so I don't understand how that would work on a website. I found instructions for Linux, but I'm running Windows.
What you need is a:
web server - to host your game. You can, for instance, rent an EC2 instance from Amazon and install there all software required (Node.js, database, ...) or go with PaaS (Platform as a Service) solution like Nodejitsu or Heroku where you'll be given Node.js out of the box.
domain - to register a human-readable name for your web serwer (like. www.my-game.com). Normally, once you get your server, it'll have some IP address assigned to it. Domain name is an alias for it, easier to type and remember. Similar to, as in your case, localhost is just an alias for an IP 127.0.0.1 (special address meaning local system).
Of course, another solution would be to host app on your local PC and set up your router to forward traffic from it's external IP to your PC (assuming your ISP assigned you public IP). But then you'll have to worry about your PC, router and internet link being always online. And it'd be way slower than when going with external, dedicated hosting.
My question is a NodeJS newbie question. I would like to somehow detect if a user is accessing my network (Wifi) and I would like to indicate the users presence in my network.
How would I go about identifying the user presence. I'm completely clueless as I was unable to find any library that could help me detect this in Node. Is this even possible? If so could you point me to the appropriate libraries and the approach that I need to use.
If you run a router like a Linksys, etc. that can support DD-WRT, you can flash that firmware and then use either SNMP or web page scraping to get connected clients. There are node.js libraries for SNMP and there are a ton of examples of web page scraping with Node.JS.
Alternatively, you could get really complicated and add in RADIUS authentication to your DD-WRT installation and watch for an authentication event.
Another option, you could send ICMP (Ping) packets to every potential address that your router would acknowledge. e.g. if it's 192.168.1.1 on a 255.255.255.0 subnet, you would have 253 addresses to ping. Of course, the connecting user's machine would have to have ICMP responses turned on (which they typically do by default).
I hope one of these suggestions helps.