diff --git a/server/api/index.js b/server/api/index.js index 302eb195..e7b0188e 100644 --- a/server/api/index.js +++ b/server/api/index.js @@ -9,6 +9,7 @@ import user from './user'; import atlases from './atlases'; import documents from './documents'; +import subdomainRedirect from './middlewares/subdomainRedirect'; import validation from './validation'; const api = new Koa(); @@ -39,6 +40,7 @@ api.use(async (ctx, next) => { } }); +api.use(subdomainRedirect()); api.use(bodyParser()); api.use(validation()); diff --git a/server/api/middlewares/subdomainRedirect.js b/server/api/middlewares/subdomainRedirect.js new file mode 100644 index 00000000..125d7058 --- /dev/null +++ b/server/api/middlewares/subdomainRedirect.js @@ -0,0 +1,12 @@ +export default function subdomainRedirect(options) { + return async function subdomainRedirectMiddleware(ctx, next) { + console.log(ctx.headers); + + if (ctx.headers['x-forwarded-proto'] != 'https') { + ctx.redirect('https://' + ctx.headers.host + ctx.path); + } + else { + return next(); + } + } +};