express-sslify icon indicating copy to clipboard operation
express-sslify copied to clipboard

enforce.HTTPS has to be called first

Open pzontrop opened this issue 6 years ago • 3 comments

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}));

pzontrop avatar Jul 12 '18 07:07 pzontrop

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.

codinggirl avatar Jul 20 '19 04:07 codinggirl

It would be good to add this to the README.

ghost avatar Dec 18 '19 18:12 ghost

Thank you, saved my evening, at least rest of it. This should really be in documentation.

tomasstorc avatar May 24 '21 19:05 tomasstorc