I have an Express.js server (v 2.5.8) (node v0.6.12) running on port 3100. It is terminated by the Nginx front end, which proxies both HTTP and https requests to port 3100.
I want to force certain urls to https. Here is an example (the application is my express server):
app.get('/applyNow', ensureSec, secure.showApplication );
secureSec is a function that I am trying to check if the connection is completed by ssl:
function ensureSec(req, res, next) {
if (req.session.ssl == true) {
return next();
} else {
req.session.ssl = true;
res.redirect('https://' + url.parse(req.headers.referer).host +
url.parse(req.url).pathname);
}
}
Redirection works, but node (after timeout) gives an error message "Unable to GET / applyNow
What is the correct way to redirect to ssl?
source
share