2019-11-07 20:39:22 +01:00
|
|
|
const config = require('../config');
|
|
|
|
const path = require('path');
|
|
|
|
const Koa = require('koa');
|
|
|
|
const serve = require('koa-static');
|
|
|
|
const logger = require('koa-logger');
|
|
|
|
const router = require('./src/routes');
|
2019-11-11 19:19:31 +01:00
|
|
|
const redirectMiddleware = require('./middleware/redirect');
|
2019-12-10 23:05:30 +01:00
|
|
|
const cacheControlMiddleware = require('./middleware/cache-control');
|
2021-02-18 22:57:52 +01:00
|
|
|
const iframeDestroyerMiddleware = require('./middleware/iframe-destroyer');
|
2019-11-07 20:39:22 +01:00
|
|
|
|
|
|
|
const app = new Koa();
|
|
|
|
const DIST_ROOT = path.resolve(__dirname, 'dist');
|
|
|
|
|
2020-04-08 22:47:06 +02:00
|
|
|
app.proxy = true;
|
|
|
|
|
2019-11-11 19:24:22 +01:00
|
|
|
app.use(async (ctx, next) => {
|
|
|
|
try {
|
|
|
|
await next();
|
|
|
|
} catch (err) {
|
2019-12-09 20:42:10 +01:00
|
|
|
console.log('error: ', err);
|
2019-11-11 19:24:22 +01:00
|
|
|
ctx.status = err.status || 500;
|
|
|
|
ctx.body = err.message;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-11-07 20:39:22 +01:00
|
|
|
app.use(logger());
|
2019-12-10 23:05:30 +01:00
|
|
|
app.use(cacheControlMiddleware);
|
2019-11-11 19:19:31 +01:00
|
|
|
app.use(redirectMiddleware);
|
2021-02-18 22:57:52 +01:00
|
|
|
app.use(iframeDestroyerMiddleware);
|
2021-06-01 15:45:04 +02:00
|
|
|
|
|
|
|
// Check if the request url matches any assets inside of /dist
|
|
|
|
app.use(serve(DIST_ROOT, {
|
|
|
|
maxage: 3600000, // set a cache time of one hour, helpful for mobile dev
|
|
|
|
}));
|
|
|
|
|
2019-11-07 20:39:22 +01:00
|
|
|
app.use(serve(DIST_ROOT)); // Check if the request url matches any assets inside of /dist
|
|
|
|
|
|
|
|
app.use(router.routes());
|
|
|
|
app.listen(config.WEB_SERVER_PORT, () => `Server up at localhost:${config.WEB_SERVER_PORT}`);
|