Skip to content

Support response headers for cases when it returns validation error #201

@maZahaca

Description

@maZahaca

First of all, thank you very much for such a great tool!

We use an API Next.js + next-rest-framework which should have cors enabled.
For the cases when response is returned from inside the handler that is fine as we can add headers as following:

return TypedNextResponse.json({}, { status: 200, headers: cors.headers });

But when framework returns a validation error we can't find a way to add such headers to 400 Validation error response.

We're adding following headers:

      'access-control-allow-headers': 'Content-Type, Authorization, Origin, ..., Referrer',
      'access-control-allow-methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
      'access-control-allow-origin': `${requestedUrl?.protocol}//${requestedUrl?.host}`,

Would be nice to:

  • capture all possible methods from this routes for proper value for access-control-allow-methods, extra added (OPTIONS covered by Next.js middleware now)
  • have a method like middleware((res)), but which happens after validation process like for our case where we can set headers manually

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions