How do I restrict to open the js file contents in browser/postman

333 views Asked by At

I am trying to restrict the code server js files to open in browser directly. Like:

http:<<domain>>:<<port>>/<<server.js>>

If I hit this url in browser the code displays as is in js file and everyone can see the js contents and all the routing and configuration. If If I will put below code in main server js file it restrict me to use the api's for front end.

app.get('/server.js', function(req, res, next) {
res.json({
    auth: false
});  });

Please help me to restrict the code to view in postman or browser.

1

There are 1 answers

0
Rahul Mankar On BEST ANSWER

I solved in adding below small script in main server.js(might be app.js/node.js in your file structure) file

app.all(['*server.js*', '*Config/**', '*Models/**', '*package.json*', '*bower.json*', '*README.md*', '*Public/**'], function (req, res, next){
    res.send({ auth: false });
});

Thank you once again nmnsud