aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoris2022-09-04 11:32:21 +0200
committerJoris2022-09-04 11:32:21 +0200
commit4428e8174445fcb36a83ee1cbb12b74632cd8b55 (patch)
tree42d84865a120d4a3c80d8646399942f530dd95d1
parent7c5a31a162eb6664eff665e0cfadc089188a5e8f (diff)
downloadbudget-4428e8174445fcb36a83ee1cbb12b74632cd8b55.tar.gz
budget-4428e8174445fcb36a83ee1cbb12b74632cd8b55.tar.bz2
budget-4428e8174445fcb36a83ee1cbb12b74632cd8b55.zip
Return content-type of assets
-rw-r--r--src/controller/utils.rs10
-rw-r--r--src/routes.rs11
2 files changed, 16 insertions, 5 deletions
diff --git a/src/controller/utils.rs b/src/controller/utils.rs
index 544cdf8..bd3007e 100644
--- a/src/controller/utils.rs
+++ b/src/controller/utils.rs
@@ -120,11 +120,17 @@ pub fn not_found() -> Response<Body> {
response
}
-pub async fn file(filename: &str) -> Response<Body> {
+pub async fn file(filename: &str, content_type: &str) -> Response<Body> {
if let Ok(file) = File::open(filename).await {
let stream = FramedRead::new(file, BytesCodec::new());
let body = Body::wrap_stream(stream);
- with_header(Response::new(body), CACHE_CONTROL, "max-age=3153600000")
+ with_headers(
+ Response::new(body),
+ vec![
+ (CACHE_CONTROL, "max-age=3153600000"),
+ (CONTENT_TYPE, content_type),
+ ],
+ )
} else {
not_found()
}
diff --git a/src/routes.rs b/src/routes.rs
index 982e5ef..7369f98 100644
--- a/src/routes.rs
+++ b/src/routes.rs
@@ -8,6 +8,7 @@ use tera::Tera;
use url::form_urlencoded;
use crate::controller;
+use crate::controller::utils::file;
use crate::controller::wallet::Wallet;
use crate::db;
use crate::model::config::Config;
@@ -40,9 +41,13 @@ pub async fn routes(
)
.await
}
- (&Method::GET, ["assets", _, file]) => {
- controller::utils::file(&format!("assets/{}", file)).await
- }
+ (&Method::GET, ["assets", _, filename]) => match *filename {
+ "main.js" => file("assets/main.js", "text/javascript").await,
+ "chart.js" => file("assets/chart.js", "text/javascript").await,
+ "main.css" => file("assets/main.css", "text/css").await,
+ "icon.png" => file("assets/icon.png", "image/png").await,
+ _ => controller::utils::not_found(),
+ },
_ => match connected_user(&pool, &request).await {
Some(user) => {
let wallet = Wallet {