node.js - Prevent direct access to html page in node js -


I would like to stop the user from typing directly in the URL of the page and going to the page. How do I get this functionality in node? I know that they do not have direct access to web applications in web applications to keep files under file.

If you are using, then you can check the referrer in the middleware like this in the middleware, Which you can further customize as necessary for your exact purposes:

  var Express = requirement ('Express') var app = express () allowed lamp = ['localhost' '127.0.0.1']; // which can link here? App.use (function (req, res, next) {var i = 0, notfound = 1, referer = req.get ('referrer'); if ((req.path === '/') || (req .path === '')) Next (); // pass call '/' always if (referrer) {while ((I and LT; permission lamp lamp) & amp; amp; not; found =) (Notfound = (referer.indexOf permission linker [i]) === - 1); i ++;}} if (notfand) {res.status (403) .seend ('protected area. Enter .mysite.com ');} else {next (); // login is allowed, go to the next step in the simple path}}); App.get ('/', function (rik, ridge) {res.send ('& lt; p & gt; Hello you are on the main page. & Lt; / p & gt; & lt; a href = "page2 "& Gt; Page 2 ; ';}); App.get (' / page2 ', function (rik, ridge) {res.send (' & lt; p & gt; 2) ;);}); app.listen (3000); // test http: // localhost: 3000   

test (and countermessor)

Can we get the main page? yes wget http: // localhost: 3000 / --2014-10-10 04: 01: 18-- http: // localhost: 3000 / resolution localhost (localhost) ... 127.0.0.1 localhost (Localhost) | 127.0.0.1 |: 3000 ... Added HTTP request sent, waiting for response ... 200 right length: 67 [text / html] Saving them: One? ??? index.html ???? / code>

Can we get another page directly? No

  wget Http: // localhost: 3000 / page2 --2014-10-10 04: 04: 34 - http: // localhost: 3000 / page2 Resolve localhost ... 127.0.0.1 from localhost Is connected. 127.0.0.1 |: 3000 ... Added HTTP request sent, waiting for response ... 403 Forbidden 2014-10-10 04:04:34 Error 403: Forbidden   

What Can we get the second page from the first page? Yes wget --referer = "http: // localhost" http: // localhost: 3000 / page2 --2014-10-10 04:05: 32 - http: // localhost: 3000 / page2 Resolving localhost (localhost) ... 127.0.0.1 is linked to localhost (localhost). 127.0.0.1 |: 3000 ... Added HTTP request sent, awaiting response ... 200 right length: 24 [text / html] Saving: One Page Page 2 < / Pre>

Can someone learn Kiddie Wget --referer to defeat this "security" plan?

Yes it only blocks honest people, not a person who really wants content.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -