I'm using Rocket multiple segments to serve static files, by this code:
#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use] extern crate rocket;
use std::path::PathBuf;
use rocket::response::NamedFile;
use std::path::Path;
#[get("/public/<file..>")]
fn files(file: PathBuf) -> Option<NamedFile> {
NamedFile::open(Path::new("static/").join(file)).ok()
}
fn main() {
rocket::ignite()
.mount("/public", routes![files])
.launch();
}
With the above server, requests for files at /public/<path..>
should be handled by returning the contents of /static/<path..>
, right?
Then on my browser, I enter the domain name along with /public/
and a multipe-segment route path, for example, a *.jpg
file, but it cannot serve the file:
As far as I check, the JPG file exists. I cannot figure out what I'm missing!
UPDATE
I also tried to use a builtin module to do so:
#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use] extern crate rocket;
use rocket_contrib::serve::StaticFiles;
fn main() {
rocket::ignite()
.mount("/public", StaticFiles::from("/static"))
.launch();
}
But it's not working either. Not sure why!