JustinBeckwith / yes-https

Say yes to https with express and connect.
MIT License
31 stars 2 forks source link

Http Requests not getting routed to Https NodeJs #5

Closed sudhanshugaur4 closed 6 years ago

sudhanshugaur4 commented 6 years ago

app.use(yes({ maxAge: 86400, // defaults 86400 includeSubdomains: true, // defaults true preload: true // defaults true
}));

Previously this code was working fine and all my requests whether Https OR Http all were getting routed to Https. But now I don't know why requests coming to Http is not getting routed to Https.

martyciz commented 6 years ago

Hi, this plugin also didn't work for me on Google App Engine Flex. I used express-sslify instead. With this extension you can set trustProtoHeader parameter as true, which looks for x-forwarded-proto header sent from App Engine.

Example code with added support for production env and health check, specific for App Engine: https://gist.github.com/martyciz/103477b4db322b6462931b33f7baf953#file-server-js

sudhanshugaur4 commented 6 years ago

Hii @martyciz actually both plugins are currently working for me. The mistake I was doing was I was putting them on the middleware after the setting the /public directory, but the right way was to put it before setting /public directory.

Right Code

app.use(yes({
  maxAge: 86400,            // defaults `86400`
  includeSubdomains: true,  // defaults `true`
  preload: true             // defaults `true`           
}));
app.use(express.static(__dirname + '/public'));

Wrong Code

app.use(express.static(__dirname + '/public'));
app.use(yes({
  maxAge: 86400,            // defaults `86400`
  includeSubdomains: true,  // defaults `true`
  preload: true             // defaults `true`           
}));

Because of which Https was not enforcing but now everything is working as expected.