Working on node app and want to make the contents of a page only available when on localhost. What is the best way/best practices to accomplish this?
Asked
Active
Viewed 268 times
2 Answers
1
put local ip restriction (eg 127.0.0.1)
refer to this stackoverflow link for more info on how to do it
1
If you are using Express, you can use this:
var express = require('express');
var app = express();
...
app.listen(3000, '127.0.0.1');
You can find more detailed explanation about this feature here: http://expressjs.com/en/api.html#app.listen
You can also achieve this with adding a rule in your firewall that will allow only connections from localhost.
-
not using express and I want to specify it on the application layer – f00 May 23 '16 at 22:15
-
The example I provided is also identical with Node’s `http.Server.listen()`. I will try to give you more precise answer if you provide more technical details. – Aleksandar Trajchevski May 23 '16 at 23:22