From 05f852fd64a4995206d8742b490c469980e9a011 Mon Sep 17 00:00:00 2001 From: Joe Biellik Date: Mon, 27 Jul 2020 20:09:58 +0100 Subject: [PATCH] Correctly handle OPTIONS --- app.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index caffebb..e8d5b5f 100644 --- a/app.js +++ b/app.js @@ -22,8 +22,14 @@ app.use(require('koa-views')(path.join(__dirname, 'views'), { extension: 'pug' })); -app.use(router.routes(), router.allowedMethods()); +app.use(router.routes()); -app.use((ctx) => ctx.throw(404)); +app.use(async (ctx, next) => { + await next(); + + if (!ctx.status || ctx.status == 404) ctx.throw(404); +}); + +app.use(router.allowedMethods()); module.exports = app;