kwhitley / itty-router

A little router.
MIT License
1.69k stars 77 forks source link

Corsify override http error code. #233

Closed AcidWeb closed 3 months ago

AcidWeb commented 3 months ago

Describe the Issue

I'm not sure if it's supposed to work that way, but enabling CORS change HTTP return code to always return 200.

Example Router Code

import { AutoRouter, cors, error } from 'itty-router'

const { preflight, corsify } = cors()

const router = AutoRouter({
  before: [preflight],
  finally: [corsify],
})

router.get('/', () => error(404))

export default { ...router }

Steps to Reproduce

  1. Run the code.
  2. Send request to /.
  3. Verify HTTP code of response.

Expected Behavior

Request should return 404.

Actual Behavior

Request return 200.

Environment:

kwhitley commented 3 months ago

Definitely not the intended behavior - thanks for catching that!

Starting the tests now~

kwhitley commented 3 months ago

Confirmed, will have a fix out momentarily!

kwhitley commented 3 months ago

Released as 5.0.6 just now :)

Thanks again for the catch!