How to match route with multiple slashes in rouille router?

I want to build a simple file server returning a html file with a directory tree, but I can't figure out how I can make a route that takes a path with "/" in rouille, using the router! macro:

    (GET) (/{path: PathBuf}) => {
    _ => Response::empty_400()

This route does not seem to match something like localhost:8000/src/ However I would like to have arbitiarily deep directories in my server root, so I would like to extract a full path from a route url. How would I do this with rouille?

cc @tomaka

I don't see a direct provision for this in the old-style macro of router! [1]. router! focuses on matching an exact path.

That said, I would use the default route _ => {} to analyze the path.

    _ => {
        let req_path = {
            let uri = request.url();
            let pos = uri.find('?').unwrap_or(uri.len());

        if request.method() == "GET" {
        } else {

I would go further and use the router! source [1] for inspiration to build a separate macro (e.g. route_path!) specifically for the (METHOD) [path] => {} syntax, and call that from router!'s default route to improve the readability of the routing DSL.



This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.