import type { HttpContext } from '@adonisjs/core/http' import type { NextFn } from '@adonisjs/core/types/http' /** * The API always answers in JSON, including the errors raised before the * route middleware (CSRF) and the EventSource requests: an unauthenticated * stream gets a 401 instead of a redirect. */ export default class ForceJsonResponseMiddleware { handle(ctx: HttpContext, next: NextFn) { if (ctx.request.url().startsWith('/api/')) { ctx.request.request.headers.accept = 'application/json' } return next() } }