-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernel.js
65 lines (60 loc) · 1.67 KB
/
kernel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict'
/** @type {import('@adonisjs/framework/src/Server')} */
const Server = use('Server')
/*
|--------------------------------------------------------------------------
| Global Middleware
|--------------------------------------------------------------------------
|
| Global middleware are executed on each http request only when the routes
| match.
|
*/
const globalMiddleware = [
'Adonis/Middleware/BodyParser',
'Adonis/Middleware/Session',
'Adonis/Middleware/Shield',
'Adonis/Middleware/AuthInit',
'App/Middleware/ConvertEmptyStringsToNull',
]
/*
|--------------------------------------------------------------------------
| Named Middleware
|--------------------------------------------------------------------------
|
| Named middleware is key/value object to conditionally add middleware on
| specific routes or group of routes.
|
| // define
| {
| auth: 'Adonis/Middleware/Auth'
| }
|
| // use
| Route.get().middleware('auth')
|
*/
const namedMiddleware = {
auth: 'Adonis/Middleware/Auth',
guest: 'Adonis/Middleware/AllowGuestOnly',
admin: 'App/Middleware/Admin',
admin_operator: 'App/Middleware/AdminOperator',
}
/*
|--------------------------------------------------------------------------
| Server Middleware
|--------------------------------------------------------------------------
|
| Server level 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(serverMiddleware)