-
-
Notifications
You must be signed in to change notification settings - Fork 257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HttpRouter with overlapping routes fails silently #4092
Comments
One option is to allow handlers fail with |
Same behavior can be observed with two wildcard routes using distinct methods: export const router = HttpRouter.empty.pipe(
HttpRouter.head("*", ViteDevHttpRouteHandler),
HttpRouter.get("*", ViteDevHttpRouteHandler),
) Fundamentally, failure happens when there are more than one catch-all routes. My app has two catch-all routes: 1) one for SSR, 2) the other for serving assets via Vite. They are added at the end of the router so any hard-coded routes takes precedence. Workaround: Initially, I created middleware but then I noticed it is not called on every request. I ended up with recovering from |
I ended up with following work around: /**
* Runs each route sequentially and returns first successful one.
*/
const FallbackHandler = pipe(
[
SolidSsrHandler,
ViteDevHttpRouteHandler,
],
Arr.map((route) =>
route.pipe(
Effect.andThen(
(res) =>
res.status === 404
? Effect.andThen(
HttpServerRequest.HttpServerRequest,
(request) => Effect.fail(new RouteNotFound({ request })),
)
: res,
),
)
),
Effect.firstSuccessOf,
)
export const router = HttpRouter.empty.pipe(
HttpRouter.get("/", HttpServerResponse.text("yo")),
HttpRouter.all("*", FallbackHandler),
) |
What version of Effect is running?
3.11.3
What steps can reproduce the bug?
https://effect.website/play/#103e73793389
What is the expected behavior?
The response is generated by first matched handler. If first handler returns 404 or some kind of an empty response, next match is executed until succesful response is returned.
What do you see instead?
Response is empty has status=500. No handler function is called as there are no logs.
Additional information
There was no error printed or thrown (I tried
Effect.tapError
)The text was updated successfully, but these errors were encountered: