I'm creating a portfolio website and some projects have static HTML demos which I'd like to serve according to the ID in the URL. The route looks like this:
#[get("/demo/<id>/<pathbuf..>")]
fn site_demo(id: usize, pathbuf: Option<PathBuf>) -> Option<NamedFile> {
// set path according to id
let demo = format!{"static/projects/{:03}/demo/", id};
// if `pathbuf` is not provided, set file to `index.html`
let pathbuf = pathbuf.unwrap_or(PathBuf::from("index.html"));
let path = Path::new(&demo).join(pathbuf);
NamedFile::open(path).ok()
}
When I type localhost:5050/demo/003/index.html
in my browser, the demo (and everything else in the demo folder) gets loaded. However, once I type just localhost:5050/demo/003/
I get this error (same result without /
at the end):
GET /demo/003/ text/html:
=> Error: No matching routes for GET /demo/003/ text/html.
=> Warning: Responding with 404 Not Found catcher.
=> Response succeeded.
I'd expect the route to match, because the PathBuf
is optional and gets set to index.html
. Would make sense to me...
Did I go wrong somewhere or should I open an issue?