1

I have my Server on Google App Engine and I am using npm module yes-https, below is the code I am writing in order to restrict the requests to Https.

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.

Can anyone please tell me why is this happening.

1 Answer 1

2

Hello actually this plugin is working perfectly fine. The mistake I was doing was I was putting yes-https 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.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Sudhanshu, can you please show me where this code would go in a React app on Google App Engine? I don't understand how this fits in to that environment. Thanks!
@Josh I didn't get you, this code is for server-side only, so what React has to do with it, maybe specifying yes-https middleware before all other's will work ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.