Skip to content
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

default or wildcard route #50

Closed
justinnoel opened this issue Jan 18, 2022 · 4 comments · Fixed by #52
Closed

default or wildcard route #50

justinnoel opened this issue Jan 18, 2022 · 4 comments · Fixed by #52

Comments

@justinnoel
Copy link
Contributor

Is there any way to create a default or wildcard route? For example, if I want to build a custom 404 handler, I can't seem to be able to do it.

Example I thought would work:

app.get("/api/abc", handleAbcRoute);
app.get("/api/*", handleCustom404);

However, the last wildcard route always takes precedence. There seems to be no way for the first route to be handled appropriately and all other routes use the handleCustom404 function.

@yusukebe yusukebe linked a pull request Jan 18, 2022 that will close this issue
@yusukebe yusukebe removed a link to a pull request Jan 18, 2022
@yusukebe yusukebe linked a pull request Jan 18, 2022 that will close this issue
@yusukebe yusukebe reopened this Jan 18, 2022
@yusukebe
Copy link
Member

Hi @justinnoel
Yes, I think what you are saying is right. So, I've implemented "default route with wildcard" in #52
Your code and example below will work.

https://github.com/yusukebe/hono/blob/98924ce16498a118687414b192c1d5769ab62f2c/example/basic/index.js#L88-L91

I released latest version as v0.0.15 by npm registry. You can try if you upgrade Hono.

@justinnoel
Copy link
Contributor Author

justinnoel commented Jan 19, 2022

Awesome! Thanks!

Trying it right now with just upgrading to Hono 0.0.15. Getting this:

Invalid state: ReadableStream is locked

This is coming from Miniflare (2.0.0). I'm going to try to resolve this and then confirm for you that the default routing is working properly.

@yusukebe
Copy link
Member

Hi @justinnoel !

I fixed bugs about ReadableStream is locked error by this PR. #55
Now, Hono 0.0.16 is released. Please try it.

@justinnoel
Copy link
Contributor Author

Woohoo 🥳! That definitely fixed the ReadableStream bug.

I've confirmed the default route feature addition is working perfectly.

Thanks so much for your amazing support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants