This repository has been archived on 2024-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
wikipedia-game-solver/apps/api/app/middleware/force_json_response_middleware.ts
Théo LUDWIG 20ab889cf8
All checks were successful
Chromatic / chromatic (push) Successful in 2m3s
CI / ci (push) Successful in 4m16s
CI / commitlint (push) Successful in 14s
chore: improve type safety Tuyau
2024-08-18 01:31:02 +01:00

15 lines
558 B
TypeScript

import type { HttpContext } from "@adonisjs/core/http"
import type { NextFn } from "@adonisjs/core/types/http"
/**
* Updating the "Accept" header to always accept "application/json" response from the server. This will force the internals of the framework like validator errors or auth errors to return a JSON response.
*/
export default class ForceJsonResponseMiddleware {
public async handle({ request }: HttpContext, next: NextFn): Promise<void> {
const headers = request.headers()
headers.accept = "application/json"
return next()
}
}