javascript - make api call only listen to localhost -


i have website constructed use api calls in same node project. want of these api calls available localhost website.

isn't there option not using oath , listen localhost?

you can put localhost port write

app.listen(port_number,'localhost',function(){    console.log('server started on '+port_number); }) 

this make whole node server start listening on localhost:port_number if want make routes listen on localhost can place middleware on calls , write code in middleware filterout calls not made local. example :-

    app.get('/first',function(req,res){     })      // middleware filter calls     app.use(function(req,res,next){       var ipofsource = request.connection.remoteaddress;       if(ipofsource == '127.0.0.1' || ipofsource == 'localhost') next();     })     // routes need need accessed localhost goes here.     app.get('/will accessible localhost',function(req,res){      })  

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -