basic error handling

This commit is contained in:
Sean Yesmunt 2019-11-11 13:24:22 -05:00
parent dbe4511c62
commit 54ddca9477

View file

@ -9,6 +9,15 @@ const redirectMiddleware = require('./middleware/redirect');
const app = new Koa();
const DIST_ROOT = path.resolve(__dirname, 'dist');
app.use(async (ctx, next) => {
try {
await next();
} catch (err) {
ctx.status = err.status || 500;
ctx.body = err.message;
}
});
app.use(logger());
app.use(redirectMiddleware);
app.use(serve(DIST_ROOT)); // Check if the request url matches any assets inside of /dist