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

How to route unknown paths? #783

Closed
silvioprog opened this issue Jan 24, 2021 · 11 comments · Fixed by #802
Closed

How to route unknown paths? #783

silvioprog opened this issue Jan 24, 2021 · 11 comments · Fixed by #802

Comments

@silvioprog
Copy link

silvioprog commented Jan 24, 2021

Hi.

I'm trying to write a reverse proxy example (#784), but I don't know how to route all possible paths. Consider the following example:

app.at("*") ... ;

now, take a look this tests below:

curl http://localhost:8080/test
ok
curl http://localhost:8080/
404
curl http://localhost:8080
404

Well, since wildcard allows anything, it should return ok in and / too. 😕

Thank you!

@jbr
Copy link
Member

jbr commented Jan 24, 2021

Is tide the right tool for a reverse proxy, vs using async-h1 directly?

@silvioprog
Copy link
Author

silvioprog commented Jan 25, 2021

@jbr It will be a naive simple example just to show how a tide-based server (instance) can handle reverse proxy.

@christoth
Copy link

I'm also trying to create a simple tide+surf based reverse-proxy.

I experienced the same behaviour and while hoping for the same expected behaviour...

The work-around I used was:
app.at("/").all(move |mut client_request: Request<()>| async move { ... });
app.at("*").all(move |mut client_request: Request<()>| async move { ... });

That combination should route all your unknown paths.

@jbr
Copy link
Member

jbr commented Jan 25, 2021

Out of curiosity to understand this use case, do you have other routes in addition to these? If not, using tide will be slower than using async-h1 directly as a reverse proxy. If there is no reason to use tide itself, we probably shouldn't include an example that doesn't use the router or other tide-specific features

@Fishrock123
Copy link
Member

Fishrock123 commented Jan 26, 2021

This is useful for custom 404's. We should support this.

@christoth
Copy link

Thanks for the guidance!
I'm working on an async-h1 reverse proxy example. It's pretty basic, as I'm learning Rust.

@spikecodes
Copy link

spikecodes commented Feb 4, 2021

The reverse proxy example would be a great addition!

@jbr
Copy link
Member

jbr commented Feb 4, 2021

@spikecodes Which, a reverse proxy or * matching /?

@spikecodes
Copy link

spikecodes commented Feb 5, 2021

My bad, I meant the reverse proxy example. I now see though that it's a separate PR: #784

@yoshuawuyts
Copy link
Member

This likely needs to be fixed in route-recognizer; I've filed an issue there: http-rs/route-recognizer#45.

@maxcountryman
Copy link

Is there a preferred method for showing a 404 page when a route isn't found with Tide today?

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.

7 participants