Subdomain redirecting
This commit is contained in:
@ -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());
|
||||
|
||||
|
@ -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();
|
@ -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'));
|
||||
|
Reference in New Issue
Block a user