kwhitley / itty-router

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

"The script will never generate a response." Exception on Cloudfare Workers #265

Closed willsmanley closed 1 month ago

willsmanley commented 1 month ago

Firstly thank you for the amazing work on this super nice router!

There might have been a change, either on the itty side or on the cloudfare side, that is causing the library to be incompatible with workers for some reason.

I ran my own thing locally and it worked great. But got this strange, unhelpful exception from cloudfare:

The script will never generate a response.

I kept banging my head into the wall until I finally tried someone's example from a blog from Nov 2023: https://www.raymondcamden.com/2023/11/17/adding-simple-routing-to-cloudflare-workers

I copied his working code exactly and got the same result, so it must be a breaking change somewhere.

To repro, just copy his code into a cloudfare worker and then invoke it. Turn on observability so that you can see the exception logged.

Please let me know if I can help dig into it further!

willsmanley commented 1 month ago

Also, howdy fellow texan

willsmanley commented 1 month ago

im assuming i should be using @cloudflare/itty-router-openapi, will try that now

willsmanley commented 1 month ago

looks like switching to @cloudflare/itty-router-openapi works, but i guess it lacks some of the sugar methods like json and error. is this what folks are recommended to do? if so it might be good to reference in the docs. i randomly stumbled upon this in a google search but it wasnt very obvious.