I have this piece of code:
var express = require('express') , http = require('http') var app = express(); var server = app.listen(1344); var io = require('socket.io').listen(server); app.use(express.static(__dirname + '/public')); app.use(express.bodyParser()); app.use(express.cookieParser()); app.use(express.session({secret: 'secret'})); app.get('/', function(req, res){ if(req.session){ console.log(req.session); } console.log('ok'); });
The code inside the app.get() callback is not called. If I comment on the line app.use(express.static(__dirname + '/public')) , then callaback works. I tried to reorder, but it looks like a lottery! I would rather know what is going on here.
I am sure that this is due to a lack of knowledge on my part about what middleware is called. Can someone help me understand this problem?
Basically, I just want to execute some logic before the files are served and index.html is loaded in the browser. By the way, placing app.get() before the line app.use(express.static()) doesn't do the trick!
limoragni
source share