Node express’s inexplicable second access log

  node.js, question

The website operation received logs similar to the following, and many more:

[2016-06-23 07:57:17][::ffff:123.56.77.64][NONE] [GET  http://www.izhongsai.com/?  t=1466639837014 - - 200] 5.280

How did you get this log? Why is there no prefix/?

The general log format should be at least as follows:

[2016-06-23 09:15:35][80.82.78.38][NONE] [GET /cache/global/img/gs.gif - - 404] 88.300

The system uses nodejs with express, and the log middleware is mogan. The reason for simple analysis is that the access log comes from inside the system, but it is not sure which part it comes from. Does the crawler bring this wonderful log?

Hope that the friends who understand this problem can solve their doubts, thank you!

I have found the answer, please refer to
http://stackoverflow.com/questions/31626234/preventing-external-requests-expressjs/31695623#31695623

Move over:

This problem can be reproduced by simulating an http format message after connecting to a web server.
Assuming that the web server is running locally, if under ubuntu, netcat can be used to send a request, such as:

netcat localhost 8080
 GET  http://example.com/path.php HTTP/1.1
 # Enter
 # Enter

Although this is not a regular http request, nodejs can still handle it correctly, but the url passed to nodejs does not only contain a path, but also includes protocols, domain names and so on. For some versions of node and express, it may kill them!

As for Mao, some will return 200, which is probably related to the way your program logic handles it!

Therefore, don’t take it for granted that the URL of the received request (the originalUrl in Express) will start with’/’,and some may not only start with’/’,but also have no correct protocol and domain name!

In express, not less than v4 version, it seems that the problem that the url does not start with’/’has been solved, but the originalUrl has not been modified and processed. No matter how many drops, it is still not necessary to think that the url must start with’/’.

To solve this problem is still relatively simple, just like the following example, put it in front of the plug-in of the log, and it will not be recorded in the log!

app.use(function(req, res, next) {
 if(req.url[0] !  == '/' || req.originalUrl[0] !  == '/') {
 res.status(404).send('');
 } else {
 next();
 bracket
 });