express-sslify
express-sslify copied to clipboard
enforce.HTTPS has to be called first
I just had a bug (on heroku) where initially I was able to load the site over http but after a refresh it redirected to the https address.
Turned out I had to put the enforce.HTTPS before any other middleware. This is not mentioned in the docs so I hope this helps people who are having the same issue.
So to sum it up: WORKS: app.use(enforce.HTTPS({trustProtoHeader: true})); app.use(express.static(path.join(__dirname, 'dist')));
DOESN'T WORK app.use(express.static(path.join(__dirname, 'dist'))); app.use(enforce.HTTPS({trustProtoHeader: true}));
This because static middleware prevent the following middlewares's excution.
So if the middleware could call the next middleware, it need not to be called first.
It would be good to add this to the README.
Thank you, saved my evening, at least rest of it. This should really be in documentation.