Reputation: 558
I have my node sails project in Google App Engine in need to redirect http to https.
With google Docs, I need to add handlers with secure: always in app.yaml file to achieve secure redirection, But its not working for me.
My app.yaml
env: flex
runtime: nodejs
manual_scaling:
instances: 1
resources:
cpu: 2
memory_gb: 8
disk_size_gb: 200
handlers:
- url: /.*
script: auto
secure: always
redirect_http_response_code: 301
env_variables:
SQL_PASSWORD: "------"
SQL_DATABASE: "-----"
INSTANCE_CONNECTION_NAME: "-----"
Am I missing anything.
Upvotes: 1
Views: 1299
Reputation: 558
App Engine Flex does not support the option secure: always for App Engine Standard it supports.
With Sails created policies for redirection with reference John Hanley Answer
config/env/production.js
module.exports = {
...
......
.........
policies:{
'*': 'isHTTPS'
}
}
api/policies/isHTTPS.js
module.exports = function(req, res, next) {
var schema = req.headers['x-forwarded-proto'] || '';
if (schema === 'https') {
// if its a request from myweb.backend.appspot.com
if (req.headers.host !== 'myweb.com') {
res.redirect('https://' + 'myweb.com' + req.url);
} else {
next();
}
} else {
// Redirect to https.
res.redirect('https://' + ((req.headers.host !== 'myweb.com') ? 'myweb.com' : req.headers.host) + req.url);
}
};
Upvotes: 1
Reputation: 81356
App Engine Flex does not support the option secure: always
That option is for App Engine Standard.
You will need to perform HTTP to HTTPS redirection in your webserver code.
Here is an example:
app.use(function(request, response){
if(!request.secure){
response.redirect("https://" + request.headers.host + request.url);
}
});
Upvotes: 1