kwhitley / itty-router

A little router.
MIT License
1.75k stars 78 forks source link

How to handle OPTIONS request? #65

Closed lakuapik closed 2 years ago

lakuapik commented 2 years ago

i try to use itty-router and deploy it to cloudflare workers. but when there is an OPTIONS request from browser it always return 404 because of router.all('*', () => new Response('404, Not Found!', { status: 404 }));

how can we handle options request to always return 200 response?


thank you for this awesome router :+1:

lakuapik commented 2 years ago

i found a simple solution like this:


const handleOptions = (req) => new Response('');

const router = Router();

router.routes.push(['OPTIONS', /(.*)/, [handleOptions]]);

if anyone has another solution, please kindly post it here too. i will close this now, thanks.