aboutsummaryrefslogtreecommitdiffstats
path: root/start/kernel.ts
diff options
context:
space:
mode:
Diffstat (limited to 'start/kernel.ts')
-rw-r--r--start/kernel.ts49
1 files changed, 49 insertions, 0 deletions
diff --git a/start/kernel.ts b/start/kernel.ts
new file mode 100644
index 0000000..1c5c92b
--- /dev/null
+++ b/start/kernel.ts
@@ -0,0 +1,49 @@
1/*
2|--------------------------------------------------------------------------
3| Application middleware
4|--------------------------------------------------------------------------
5|
6| This file is used to define middleware for HTTP requests. You can register
7| middleware as a `closure` or an IoC container binding. The bindings are
8| preferred, since they keep this file clean.
9|
10*/
11
12import Server from '@ioc:Adonis/Core/Server';
13
14/*
15|--------------------------------------------------------------------------
16| Global middleware
17|--------------------------------------------------------------------------
18|
19| An array of global middleware, that will be executed in the order they
20| are defined for every HTTP requests.
21|
22*/
23Server.middleware.register([
24 () => import('@ioc:Adonis/Core/BodyParser'),
25 () => import('@ioc:Adonis/Addons/Shield'),
26]);
27
28/*
29|--------------------------------------------------------------------------
30| Named middleware
31|--------------------------------------------------------------------------
32|
33| Named middleware are defined as key-value pair. The value is the namespace
34| or middleware function and key is the alias. Later you can use these
35| alias on individual routes. For example:
36|
37| { auth: () => import('App/Middleware/Auth') }
38|
39| and then use it as follows
40|
41| Route.get('dashboard', 'UserController.dashboard').middleware('auth')
42|
43*/
44Server.middleware.registerNamed({
45 auth: () => import('App/Middleware/Auth'),
46 dashboard: () => import('App/Middleware/Dashboard'),
47 guest: () => import('App/Middleware/AllowGuestOnly'),
48 shield: () => import('@ioc:Adonis/Addons/Shield'),
49});