I'm developing a node.js web server that runs express/express-session/passport for authentication and socket.io for websockets. The web server itself is reverse proxied with Nginx.
Everything seems to work fine and the server can correctly grab the clients information, but when I proxy the site behind Cloudflare, it gets stuck on the auth page.
app.get('/', function (req, res) {
//successfully authenticated
if (req.session && req.session.passport && req.session.passport.user) {
res.sendFile('index.html', { root: 'client/html' });
console.log('Index Served');
}
//request authentication
else {
res.sendFile('auth.html', { root: 'client/html' });
console.log('Auth Served');
};
});
However, I do get "Index Served" in the console, so the authentication seems to be working fine behind Cloudflare. I can even see the players information in the console. I just don't see index.html- I only get auth.html even though "Index Served" is getting sent to the console, so maybe its an express issue?
I have both app.set('trust proxy', true); and proxy set to true in the session parameters.
The following does not seem to run when I proxy the server, as I only see the following console logs when I do not have it proxied:
//dependency: websocket
var io = require('socket.io')(server);
io.use(function(socket, next){
console.log('1 ' + socket);
socket.client.request.originalUrl = socket.client.request.url;
cookieParse(socket.client.request, socket.client.request.res, next);
});
io.use(function(socket, next){
console.log('2 ' + socket);
socket.client.request.originalUrl = socket.client.request.url;
sessionAuthentication(socket.client.request, socket.client.request.res, next);
});
io.use(function(socket, next){
console.log('3 ' + socket);
passportInit(socket.client.request, socket.client.request.res, next);
});
io.use(function(socket, next){
console.log('4 ' + socket);
passportSession(socket.client.request, socket.client.request.res, next);
});
I have the web server running on port 2052, which according the Cloudflare is a proper port for websockets: https://developers.cloudflare.com/fundamentals/get-started/reference/network-ports/
I don't really have a good idea of what's going on, so I want to know what I can do to debug it? I have checked the access and error logs of Nginx and don't get anything useful. Is there a way for me to debug socket.io somehow or maybe express-session?
The entire server.js file can be seen here: https://github.com/Dan-Mizu/Project-Virtual-Pond/blob/update/server/Server.js