Skip to content

Instantly share code, notes, and snippets.

@shanelau
Created August 28, 2017 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shanelau/2e3c46a95af4a51e7600d0b432eeaf0b to your computer and use it in GitHub Desktop.
Save shanelau/2e3c46a95af4a51e7600d0b432eeaf0b to your computer and use it in GitHub Desktop.
http redirect to https
if (app.config.env === 'prod') {
// SLB 的 https 会添加 请求头部 x-forwarded-proto
const isHttps = this.ctx.request.headers['x-forwarded-proto'] && (this.ctx.request.headers['x-forwarded-proto'] === 'https');
if (!isHttps) {
return this.ctx.redirect(this.ctx.href.replace('http://', 'https://'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment