kernel.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. 'use strict'
  2. /** @type {import('@adonisjs/framework/src/Server')} */
  3. const Server = use('Server')
  4. /*
  5. |--------------------------------------------------------------------------
  6. | Global Middleware
  7. |--------------------------------------------------------------------------
  8. |
  9. | Global middleware are executed on each http request only when the routes
  10. | match.
  11. |
  12. */
  13. const globalMiddleware = [
  14. 'Adonis/Middleware/BodyParser',
  15. 'Adonis/Middleware/Session',
  16. 'Adonis/Middleware/Shield',
  17. 'Adonis/Middleware/AuthInit',
  18. 'App/Middleware/ConvertEmptyStringsToNull',
  19. 'App/Middleware/Locale'
  20. ]
  21. /*
  22. |--------------------------------------------------------------------------
  23. | Named Middleware
  24. |--------------------------------------------------------------------------
  25. |
  26. | Named middleware is key/value object to conditionally add middleware on
  27. | specific routes or group of routes.
  28. |
  29. | // define
  30. | {
  31. | auth: 'Adonis/Middleware/Auth'
  32. | }
  33. |
  34. | // use
  35. | Route.get().middleware('auth')
  36. |
  37. */
  38. const namedMiddleware = {
  39. auth: 'Adonis/Middleware/Auth',
  40. guest: 'Adonis/Middleware/AllowGuestOnly'
  41. }
  42. /*
  43. |--------------------------------------------------------------------------
  44. | Server Middleware
  45. |--------------------------------------------------------------------------
  46. |
  47. | Server level middleware are executed even when route for a given URL is
  48. | not registered. Features like `static assets` and `cors` needs better
  49. | control over request lifecycle.
  50. |
  51. */
  52. const serverMiddleware = [
  53. 'Adonis/Middleware/Static',
  54. 'Adonis/Middleware/Cors'
  55. ]
  56. Server
  57. .registerGlobal(globalMiddleware)
  58. .registerNamed(namedMiddleware)
  59. .use(serverMiddleware)