From 941c07bdaf3ad4dac8cdc6cdda2a517ce55026ed Mon Sep 17 00:00:00 2001 From: neri Date: Tue, 14 Jul 2020 13:45:14 +0200 Subject: [PATCH] no compression, better http caching, better css --- Cargo.lock | 43 --------------------------------- Cargo.toml | 2 +- README.md | 2 ++ src/main.rs | 7 ++---- static/index.css | 10 ++++++-- {template => static}/index.html | 0 6 files changed, 13 insertions(+), 51 deletions(-) rename {template => static}/index.html (100%) diff --git a/Cargo.lock b/Cargo.lock index 3738097..4d294f2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -69,14 +69,12 @@ dependencies = [ "actix-utils", "base64 0.11.0", "bitflags", - "brotli2", "bytes", "chrono", "copyless", "derive_more", "either", "encoding_rs", - "flate2", "futures-channel", "futures-core", "futures-util", @@ -508,26 +506,6 @@ dependencies = [ "waker-fn", ] -[[package]] -name = "brotli-sys" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4445dea95f4c2b41cde57cc9fee236ae4dbae88d8fcbdb4750fc1bb5d86aaecd" -dependencies = [ - "cc", - "libc", -] - -[[package]] -name = "brotli2" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cb036c3eade309815c15ddbacec5b22c4d1f3983a774ab2eac2e3e9ea85568e" -dependencies = [ - "brotli-sys", - "libc", -] - [[package]] name = "bumpalo" version = "3.4.0" @@ -633,15 +611,6 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" -[[package]] -name = "crc32fast" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" -dependencies = [ - "cfg-if", -] - [[package]] name = "crossbeam-queue" version = "0.2.3" @@ -799,18 +768,6 @@ version = "1.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "36a9cb09840f81cd211e435d00a4e487edd263dc3c8ff815c32dd76ad668ebed" -[[package]] -name = "flate2" -version = "1.0.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68c90b0fc46cf89d227cc78b40e494ff81287a92dd07631e5af0d06fe3cf885e" -dependencies = [ - "cfg-if", - "crc32fast", - "libc", - "miniz_oxide", -] - [[package]] name = "fnv" version = "1.0.7" diff --git a/Cargo.toml b/Cargo.toml index ecd0caf..15ce839 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -actix-web = { version = "2.0.0", default-features = false, features = [ "compress" ] } +actix-web = { version = "2.0.0", default-features = false, features = [] } sqlx = { version = "0.3.5", default-features = false, features = [ "runtime-async-std", "postgres", "chrono" ] } actix-rt = "1.1.1" env_logger = "0.7.1" diff --git a/README.md b/README.md index 1d124ce..718c803 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,8 @@ docker-compose up -d --build ## running & config +The static files directory needs to be next to the binary. + | environment variable | default value | | -------------------- | --------------------- | | DATABASE_URL | postresql://localhost | diff --git a/src/main.rs b/src/main.rs index 304e26c..1e9b36f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,14 +24,11 @@ use sqlx::{ }; use std::env; -const INDEX_HTML: &str = include_str!("../template/index.html"); const UPLOAD_HTML: &str = include_str!("../template/upload.html"); const VIEW_HTML: &str = include_str!("../template/view.html"); -async fn index() -> Result { - Ok(HttpResponse::Ok() - .content_type("text/html") - .body(INDEX_HTML)) +async fn index() -> Result { + Ok(NamedFile::open("static/index.html").map_err(|_| error::ErrorNotFound(""))?) } async fn upload( diff --git a/static/index.css b/static/index.css index 4aaa4a7..0923a96 100644 --- a/static/index.css +++ b/static/index.css @@ -31,8 +31,7 @@ label { input, select, textarea, -.button, -.button:visited { +.button { background-color: #222222; color: #dddddd; padding: 0.5rem; @@ -44,9 +43,16 @@ textarea, .button { cursor: pointer; +} + +a.button { text-decoration: none; } +a.button:visited { + color: #dddddd; +} + .button:hover { background-color: #444444; } diff --git a/template/index.html b/static/index.html similarity index 100% rename from template/index.html rename to static/index.html