diff options
Diffstat (limited to 'start/kernel.ts')
-rw-r--r-- | start/kernel.ts | 55 |
1 files changed, 10 insertions, 45 deletions
diff --git a/start/kernel.ts b/start/kernel.ts index 0081844..86ec933 100644 --- a/start/kernel.ts +++ b/start/kernel.ts | |||
@@ -1,49 +1,14 @@ | |||
1 | /* | 1 | import server from '@adonisjs/core/services/server'; |
2 | |-------------------------------------------------------------------------- | 2 | import router from '@adonisjs/core/services/router'; |
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 | 3 | ||
12 | import { server } from '@adonisjs/core/services/server'; | 4 | server.use([ |
13 | 5 | () => import('@adonisjs/core/bodyparser_middleware'), | |
14 | /* | 6 | () => import('@adonisjs/shield/shield_middleware'), |
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 | */ | ||
23 | server.middleware.register([ | ||
24 | () => import('@ioc:Adonis/Core/BodyParser'), | ||
25 | () => import('@ioc:Adonis/Addons/Shield'), | ||
26 | ]); | 7 | ]); |
27 | 8 | ||
28 | /* | 9 | router.named({ |
29 | |-------------------------------------------------------------------------- | 10 | auth: () => import('#app/Middleware/Auth'), |
30 | | Named middleware | 11 | dashboard: () => import('#app/Middleware/Dashboard'), |
31 | |-------------------------------------------------------------------------- | 12 | guest: () => import('#app/Middleware/AllowGuestOnly'), |
32 | | | 13 | shield: () => import('@adonisjs/shield/shield_middleware'), |
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 | */ | ||
44 | server.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 | }); | 14 | }); |