Monday 13 March 2017

Only some routes work on Node express

I've been developing a website for a while now locally. Using Ubuntu, nodejs and express. I recently moved it to my VPS on Dreamhost and it has some strange behavior. Everything worked fine on my localhost but on the VPS only some routes work. By this I mean if I go to mydomain.com then I get the website. Then if I go to mydomain.com/panel it loads, however, it is supposed to check for a user session but doesn't, it just sends them to the panel. Then if I try to go to mydomain.com/contact or any other route on my website, it just won't load. I get a 500 error.

This is my panel route, which is found in routes/panel.js

router.get('/', function(req, res, next) {
  var sess = req.session;
  if(sess.user) res.status(200).sendFile(path.resolve(__dirname + '/../public/panel.html'));
  else res.status(200).sendFile(path.resolve(__dirname + '/../public/admin.html'));
});

This is my contact route, which is found in routes/contact.js

router.get('/', function(req, res) {
  res.send("Hello");
});

In app.js I add both of these routes like this,

app.use('/contact', contact);
app.use('/panel', panel);

This all works on my localhost. All of the correct modules are present. For some reason it is not working on the Dreamhost VPS.

Any ideas?



via Gary Johnson

No comments:

Post a Comment