55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
|
/**
|
||
|
* HTTP kernel file
|
||
|
*
|
||
|
* The HTTP kernel file is used to register the middleware with the server or the router.
|
||
|
*/
|
||
|
|
||
|
import router from "@adonisjs/core/services/router"
|
||
|
import server from "@adonisjs/core/services/server"
|
||
|
|
||
|
/**
|
||
|
* The error handler is used to convert an exception
|
||
|
* to a HTTP response.
|
||
|
*/
|
||
|
server.errorHandler(async () => {
|
||
|
return await import("#app/exceptions/handler.js")
|
||
|
})
|
||
|
|
||
|
/**
|
||
|
* The server middleware stack runs middleware on all the HTTP
|
||
|
* requests, even if there is no route registered for
|
||
|
* the request URL.
|
||
|
*/
|
||
|
server.use([
|
||
|
async () => {
|
||
|
return await import("#app/middleware/container_bindings_middleware.js")
|
||
|
},
|
||
|
async () => {
|
||
|
return await import("#app/middleware/force_json_response_middleware.js")
|
||
|
},
|
||
|
async () => {
|
||
|
return await import("@adonisjs/cors/cors_middleware")
|
||
|
},
|
||
|
])
|
||
|
|
||
|
/**
|
||
|
* The router middleware stack runs middleware on all the HTTP requests with a registered route.
|
||
|
*/
|
||
|
router.use([
|
||
|
async () => {
|
||
|
return await import("@adonisjs/core/bodyparser_middleware")
|
||
|
},
|
||
|
async () => {
|
||
|
return await import("@adonisjs/auth/initialize_auth_middleware")
|
||
|
},
|
||
|
])
|
||
|
|
||
|
/**
|
||
|
* Named middleware collection must be explicitly assigned to the routes or the routes group.
|
||
|
*/
|
||
|
export const middleware = router.named({
|
||
|
auth: async () => {
|
||
|
return await import("#app/middleware/auth_middleware.js")
|
||
|
},
|
||
|
})
|