From 22f43b4012fc1e089717c14c282178f26dc17103 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Sun, 3 Sep 2017 22:11:34 +0530 Subject: [PATCH] fix(kernel): add cors as server middleware --- start/kernel.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/start/kernel.js b/start/kernel.js index 0149871..72d769e 100644 --- a/start/kernel.js +++ b/start/kernel.js @@ -13,7 +13,6 @@ const Server = use('Server') */ const globalMiddleware = [ 'Adonis/Middleware/BodyParser', - 'Adonis/Middleware/Cors', 'Adonis/Middleware/Session', 'Adonis/Middleware/Shield', 'Adonis/Middleware/AuthInit' @@ -40,7 +39,22 @@ const namedMiddleware = { auth: 'Adonis/Middleware/Auth' } +/* +|-------------------------------------------------------------------------- +| Server Middleware +|-------------------------------------------------------------------------- +| +| Server levl middleware are executed even when route for a given URL is +| not registered. Features like `static assets` and `cors` needs better +| control over request lifecycle. +| +*/ +const serverMiddleware = [ + 'Adonis/Middleware/Static', + 'Adonis/Middleware/Cors' +] + Server .registerGlobal(globalMiddleware) .registerNamed(namedMiddleware) - .use(['Adonis/Middleware/Static']) + .use(serverMiddleware)