Reputation: 7654
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.
Upvotes: 1
Views: 532
Reputation: 7654
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.
Upvotes: 2