kernel.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. import Server from '@ioc:Adonis/Core/Server'
  12. /*
  13. |--------------------------------------------------------------------------
  14. | Global middleware
  15. |--------------------------------------------------------------------------
  16. |
  17. | An array of global middleware, that will be executed in the order they
  18. | are defined for every HTTP requests.
  19. |
  20. */
  21. Server.middleware.register([
  22. () => import('@ioc:Adonis/Core/BodyParser'),
  23. () => import('App/Middleware/SilentAuth')
  24. ])
  25. /*
  26. |--------------------------------------------------------------------------
  27. | Named middleware
  28. |--------------------------------------------------------------------------
  29. |
  30. | Named middleware are defined as key-value pair. The value is the namespace
  31. | or middleware function and key is the alias. Later you can use these
  32. | alias on individual routes. For example:
  33. |
  34. | { auth: () => import('App/Middleware/Auth') }
  35. |
  36. | and then use it as follows
  37. |
  38. | Route.get('dashboard', 'UserController.dashboard').middleware('auth')
  39. |
  40. */
  41. Server.middleware.registerNamed({
  42. auth: () => import('App/Middleware/Auth')
  43. })