javascript - Restrict access to Node.js using Express -


i have running node.js script located in server. want doesn't directly accessed browser , want domains/ip-s can call it! possible?!

not sure how distinguishing between accessing browser opposed other software, restricting access domains/ips should doable. following (non production) code restrict access localhost loop might serve starting point:

function securitycheck( req, response, next) {    var callerip = req.connection.remoteaddress;      (callerip == "::ffff:127.0.0.1" || callerip == "::1") ? next() : reply404( response); }  function reply404( response) {   response.writehead(404, {"content-type": "text/html"});     response.statusmessage = "not found";     console.log("reply404: statuscode: " + response.statuscode);     response.end('<span style="font-weight: bold; font-size:200%;">error 404 &ndash; not found<\/span>'); } var app = express(); app.use(securitycheck);  // restrict access ... // continue app routing 

see more detailed answers express.js: how remote client address , how domain originating request in express.js?


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -