I have a node.js server with express.js and everything has been working well so far, but suddenly I have this very strange bug :
My request to the domain base URL that means in my browser I typed
http://localhost:9191/
appear in express to have the url parameters /index/hud.html which by the way have never been used anywhere in my code as I don't have any "index" folder. I don't even have html files because I use jade. This URL is not totally unknown of me (from old code, elsewhere), but is nowhere mentionned in this server. I have made numerous search accross all files to check this.
So here is what happens :
'*' so I could know what was going on :The handler
this.app.get('*', function (req, res) {
console.log(req);
});
The req object (part of) :
route: {
path: '*',
method: 'get',
callbacks: [ [Function] ],
keys: [],
regexp: /^(.*)\/?$/i,
params: [ '/index/hud.html' ]
},
params: [ '/index/hud.html' ] }
Which means that my browser somehow wants to get something that is not the URL I typed, or maybe express modified the request ?
Then I made a handler for this url. My first guess was to redirect it to '/' but it made an infinite loop (which means that for my server '/index/hud.html' is the same as '/'. Please note at this point that I searched and researched in every file, there is no mention of such path anywhere in the code.
The request catched from '/index/hud.html' is a little bit different than the one catched from '/'
The handler :
this.app.get('/index/hud.html', function (req, res)
{
console.log(req);
});
The request :
route:
{
path: '/index/hud.html',
method: 'get',
callbacks: [ [Function] ],
keys: [],
regexp: /^\/index\/hud\.html\/?$/i,
params: []
},
params: [] }
I also tried deleting browser cache and everything (and changing browser) but it seems to really be express that add these parameters somehow... Anyone have an idea what is going on ?
Ok auto answer :
I had a index.html sitting in the root of my public folder.
Apparently, a request to '/' asks for a public index file before going to express's request handlers. That means my '/' handler could never be called, and so I couldn't be informed that an index.html file was served.
Then, on that index file is an iframe asking for index/hud.html (didn't find that one through searching :( ) which doesn't exist in my public folder, creating this time an express get request that I could catch with my '*' handler, pointing to /index/hud.html
So deleting this index.html made the request follow the right path, instead of just getting an html file.