diff --git a/server/api/index.js b/server/api/index.js index e7b0188ee..302eb1953 100644 --- a/server/api/index.js +++ b/server/api/index.js @@ -9,7 +9,6 @@ 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(); @@ -40,7 +39,6 @@ api.use(async (ctx, next) => { } }); -api.use(subdomainRedirect()); api.use(bodyParser()); api.use(validation()); diff --git a/server/api/middlewares/subdomainRedirect.js b/server/middlewares/subdomainRedirects.js similarity index 62% rename from server/api/middlewares/subdomainRedirect.js rename to server/middlewares/subdomainRedirects.js index 125d70584..631b12e15 100644 --- a/server/api/middlewares/subdomainRedirect.js +++ b/server/middlewares/subdomainRedirects.js @@ -2,8 +2,8 @@ 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); + if (ctx.headers.host === 'beautifulatlas.com') { + ctx.redirect('https://wwww.' + ctx.headers.host + ctx.path); } else { return next(); diff --git a/server/routes.js b/server/routes.js index 89f5e31d3..31d9b3711 100644 --- a/server/routes.js +++ b/server/routes.js @@ -4,6 +4,8 @@ import Koa from 'koa'; import Router from 'koa-router'; import sendfile from 'koa-sendfile'; +import subdomainRedirect from './middlewares/subdomainRedirect'; + const koa = new Koa(); const router = new Router(); @@ -33,6 +35,8 @@ if (process.env.NODE_ENV === 'production') { const stats = await sendfile(ctx, path.join(__dirname, '../dist/index.html')); if (!ctx.status) ctx.throw(httpErrors.NotFound()); }); + + koa.use(subdomainRedirect()); } else { router.get('*', async (ctx) => { const stats = await sendfile(ctx, path.join(__dirname, './static/dev.html'));