2020-01-14 01:57:43 +00:00
|
|
|
'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.
|
|
|
|
|
|
|
|
|
*/
|
2020-02-02 22:42:18 +00:00
|
|
|
const globalMiddleware =
|
|
|
|
[
|
|
|
|
'Adonis/Middleware/BodyParser',
|
|
|
|
'Adonis/Middleware/Session',
|
|
|
|
'Adonis/Middleware/Shield',
|
|
|
|
'Adonis/Middleware/AuthInit',
|
|
|
|
'App/Middleware/ConvertEmptyStringsToNull',
|
|
|
|
]
|
2020-01-14 01:57:43 +00:00
|
|
|
|
2020-02-02 22:42:18 +00:00
|
|
|
/*
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
| 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',
|
2020-03-17 22:16:34 +00:00
|
|
|
guest: 'Adonis/Middleware/AllowGuestOnly',
|
|
|
|
adminAuth: 'App/Middleware/AdminAuth',
|
2020-04-30 02:34:14 +00:00
|
|
|
BookPageAuth: 'App/Middleware/BookPageAuth',
|
|
|
|
BookContext: 'App/Middleware/BookContext',
|
|
|
|
CallContext: 'App/Middleware/CallContext',
|
2020-02-02 22:42:18 +00:00
|
|
|
}
|
2020-01-14 01:57:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
| 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.
|
|
|
|
|
|
|
|
|
*/
|
2020-02-02 22:42:18 +00:00
|
|
|
const serverMiddleware = ['Adonis/Middleware/Static', 'Adonis/Middleware/Cors']
|
2020-01-14 01:57:43 +00:00
|
|
|
|
2020-02-02 22:42:18 +00:00
|
|
|
Server.registerGlobal(globalMiddleware)
|
|
|
|
.registerNamed(namedMiddleware)
|
|
|
|
.use(serverMiddleware);
|