aboutsummaryrefslogtreecommitdiff
path: root/src/routes.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes.rs')
-rw-r--r--src/routes.rs22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/routes.rs b/src/routes.rs
index ae97b7a..509f1b2 100644
--- a/src/routes.rs
+++ b/src/routes.rs
@@ -17,6 +17,10 @@ use crate::model;
use crate::templates;
use crate::util;
+static MAIN_JS: &[u8] = include_bytes!("static/main.js");
+static MAIN_CSS: &[u8] = include_bytes!("static/main.css");
+static ICON_PNG: &[u8] = include_bytes!("static/icon.png");
+
pub async fn routes(
request: Request<Incoming>,
db_conn: Connection,
@@ -29,12 +33,12 @@ pub async fn routes(
match (request.method(), path_parts) {
(&Method::GET, []) => Ok(html(templates::INDEX)),
- (&Method::GET, ["static", "main.js"]) => Ok(static_file(
- include_str!("static/main.js"),
- "application/javascript",
- )),
+ (&Method::GET, ["static", "main.js"]) =>
+ Ok(static_file(MAIN_JS, "application/javascript")),
+ (&Method::GET, ["static", "icon.png"]) =>
+ Ok(static_file(ICON_PNG, "image/png")),
(&Method::GET, ["static", "main.css"]) => {
- Ok(static_file(include_str!("static/main.css"), "text/css"))
+ Ok(static_file(MAIN_CSS, "text/css"))
}
(&Method::POST, ["upload"]) => {
upload_file(request, db_conn, authorized_key, files_dir).await
@@ -146,15 +150,11 @@ async fn get(
}
fn static_file(
- text: impl Into<String>,
+ content: &'static[u8],
content_type: &str,
) -> Response<BoxBody<Bytes, std::io::Error>> {
let response = Response::builder()
- .body(
- Full::new(text.into().into())
- .map_err(|e| match e {})
- .boxed(),
- )
+ .body(Full::new(content.into()).map_err(|e| match e {}).boxed())
.unwrap();
with_headers(response, vec![(CONTENT_TYPE, content_type)])
}