Mercurial > lbo > hg > geohub
changeset 13:9c6ae7990f63
Add static file serving and limit workers
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Wed, 02 Dec 2020 19:07:34 +0100 |
parents | 098d717f50ae |
children | c0b83e11f1f1 |
files | Rocket.toml src/main.rs |
diffstat | 2 files changed, 14 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/Rocket.toml Tue Dec 01 23:15:23 2020 +0100 +++ b/Rocket.toml Wed Dec 02 19:07:34 2020 +0100 @@ -1,7 +1,11 @@ [global.databases] geohub = { url = "postgresql://lbo:pglbo@localhost/lbo" } +[development] +workers = 5 + [production] log = "normal" address = "::1" port = 8000 +workers = 5
--- a/src/main.rs Tue Dec 01 23:15:23 2020 +0100 +++ b/src/main.rs Wed Dec 02 19:07:34 2020 +0100 @@ -290,9 +290,18 @@ rocket::http::Status::Ok } +/// Serve static files +#[rocket::get("/geo/assets/<file..>")] +fn assets( + file: std::path::PathBuf, +) -> Result<rocket::response::NamedFile, rocket::response::status::NotFound<String>> { + let p = std::path::Path::new("assets/").join(file); + rocket::response::NamedFile::open(&p).map_err(|e| rocket::response::status::NotFound(e.to_string())) +} + fn main() { rocket::ignite() .attach(DBConn::fairing()) - .mount("/", rocket::routes![log, retrieve_json, retrieve_live]) + .mount("/", rocket::routes![log, retrieve_json, retrieve_live, assets]) .launch(); }