fermyon / spin-js-sdk

https://developer.fermyon.com/spin/javascript-components
Apache License 2.0
52 stars 18 forks source link

Router should have default 404 handler #172

Open rylev opened 1 year ago

rylev commented 1 year ago

When a request goes through the router for which there is no route defined, a very cryptic message is thrown. We should at least provide some sort of default handling of an unrecognized request.

karthik2804 commented 1 year ago

The router does support the match-all syntax which can be added as the last entry to catch all routes that do not match. It is how itty-router is implemented. Would that be sufficient in this case.

router.all("*", ...)

I personally think that there should be no default route handling because there are cases where I would want to use a router to be triggered only on specific routes.

rylev commented 1 year ago

I suppose that would be sufficient. I simply found it surprising that the router wasn't catching unknown routes, but if we give the user a good way to do this (and display it prominently in the docs, that is probably good enough.

ThorstenHans commented 10 months ago

I think there are two ways of approaching this:

  1. The Router should provide the same behavior as popular/common routers provided by other frameworks of the particular language (JS/TS here).
  2. The Router should provide the same behavior across all Spin SDKs.

Initially, I thought option 2 would be the best way to go. Option 2 would be especially useful for developers using multiple languages to craft Spin applications.

On the flip side, option 1 would smoothen the adoption for JS developers, because they expect the router to behave in a certain way.