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

Nested endpoints have less priority than wildcards #911

Open
fawni opened this issue Aug 11, 2023 · 0 comments
Open

Nested endpoints have less priority than wildcards #911

fawni opened this issue Aug 11, 2023 · 0 comments

Comments

@fawni
Copy link

fawni commented Aug 11, 2023

using a wildcard path is the only way to handle 404 errors in tide as far as i'm aware. however, tide ignores nested endpoints and treats them like undefined paths.

here's an example:

#[async_std::main]
async fn main() -> Result<(), tide::Error> {
    let mut app = tide::new();
    app.at("/hello").get(|_| async move { Ok("hello") });
    app.at("/orders").nest({
        let mut orders = tide::new();
        orders.at("/shoes").get(|_| async move { Ok("shoes") });
        orders.at("/shirts").get(|_| async move { Ok("shirts") });
        orders
    });
    app.at("*").get(|_| async move { Ok("404") });
    async_std::task::spawn(app.listen("0.0.0.0:8080"));

    assert_eq!(surf::get("http://localhost:8080/hello").recv_string().await?, "hello");
    assert_eq!(surf::get("http://localhost:8080/orders/shoes").recv_string().await?, "shoes");
    Ok(())
}

which returns:

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `"404"`,
 right: `"shoes"`', src\main.rs:15:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

using tide version 0.16.0 at the time of writing this.

/orders/shoes is handled and should return "shoes" but instead it is ignored and returns "404". this is not the case with non nested routes such as /hello in the example.

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

No branches or pull requests

1 participant