tsndr / cloudflare-worker-router

A super lightweight router (1.0K) with middleware support and ZERO dependencies for Cloudflare Workers.
MIT License
227 stars 30 forks source link

Default route possible? #17

Closed grempe closed 2 years ago

grempe commented 2 years ago

Is it possible to have a default route that, for example, would return a 404 for any request that does not match an existing route?

e.g. in Express

app.get(/.*/, (req, res) => {
  res.status(404).send();
  //res.json({ status: ":(" });
});

https://stackoverflow.com/questions/37988122/404-fallback-route-in-express

tsndr commented 2 years ago

That's a great idea, currently it's hardcoded to 404 right here. This goes onto my todo list, thank you :)

grempe commented 2 years ago

Actually, it's not a 404 that gets returned by default. Its a 204 No Content which is confusing.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/204

tsndr commented 2 years ago

I'm sorry, I linked to the wrong line, but it's still 404, this is the correct line right here.

grempe commented 2 years ago

Hi. You closed this issue but I don't see how the recent release addresses this and there seems to be no update to the README.

Did I miss something? Thx

tsndr commented 2 years ago

Oh, I was thinking that you just wanted 404 to be returned as default, which is already the case and since you didn't ansewer I closed it.

tsndr commented 2 years ago

Here you go :) #19

tsndr commented 2 years ago

Released with v1.3.7