import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'

export default class RestrictHttpMethods {
  public async handle({ request, response }: HttpContextContract, next: () => Promise<void>) {
    const forbiddenMethods = ['TRACE', 'PUT', 'DELETE', 'OPTIONS']
    if (forbiddenMethods.includes(request.method())) {
      return response.status(405).send('Method Not Allowed')
    }
    await next()
  }
}