Skip to content

Nested endpoints have less priority than wildcards #911

@fawni

Description

@fawni

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions