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:
This route does not seem to match something like localhost:8000/src/main.rs. 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?
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.
router!(request,
_ => {
let req_path = {
let uri = request.url();
let pos = uri.find('?').unwrap_or(uri.len());
&uri[..pos]
};
if request.method() == "GET" {
handle_path(req_path.as_path())
} else {
Response::empty_404()
}
}
}
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.