Skip to content
Discussion options

You must be logged in to vote

The afterResponse hook only runs when the actual request completes. if it doesnt run with CORS preflight requests, its likely because:

the preflight request is failing
check the Network tab - if the OPTIONS request fails (CORS error), the main request never gets sent, so no hook runs.

or the server isnt handling preflight correctly:
the server needs to respond to OPTIONS requests with proper CORS headers:

  • Access-Control-Allow-Origin
  • Access-Control-Allow-Methods
  • Access-Control-Allow-Headers

or network error during preflight:
if theres a network error before the main request, hooks wont execute.

to debug, check the Network tab for:

OPTIONS /api/endpoint (status 200 or 204 = good)
GET/POST…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@llaz00
Comment options

Answer selected by sindresorhus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants