Subdomain redirecting

This commit is contained in:
Jori Lallo
2016-05-27 00:06:36 -07:00
parent eab41436a6
commit a0f86f5ed4
3 changed files with 6 additions and 4 deletions

View File

@ -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());

View File

@ -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();

View File

@ -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'));