From 314b237bb7d67cb2426a0302f993f1384bb35a37 Mon Sep 17 00:00:00 2001 From: ngn Date: Mon, 20 Jan 2025 05:54:35 +0300 Subject: [PATCH] add static route for main.css Signed-off-by: ngn --- Dockerfile | 16 +++++++++++----- build.rs | 2 +- config.toml | 2 +- src/main.rs | 2 ++ src/settings.rs | 10 ++-------- {templates => static}/main.css | 0 templates/index.html | 4 +--- templates/post.html | 3 --- templates/post_meta.html | 1 + 9 files changed, 19 insertions(+), 21 deletions(-) rename {templates => static}/main.css (100%) diff --git a/Dockerfile b/Dockerfile index e46ac86..5efaead 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,11 +15,17 @@ RUN cargo build --release FROM debian:bookworm-slim -RUN useradd -ms /bin/bash -u 1001 libmedium -RUN apt-get update && apt-get install -y ca-certificates -RUN mkdir /var/lib/libmedium && chown libmedium /var/lib/libmedium +RUN useradd -d /app -u 1001 -g 1001 libmedium +RUN apt-get update +RUN apt-get install -y ca-certificates -COPY --from=rust /src/target/release/libmedium /usr/local/bin/ +WORKDIR /app + +COPY --from=rust /src/target/release/libmedium ./ +COPY --from=rust /src/config.toml ./ +COPY --from=rust /src/static ./static + +RUN chown libmedium:libmedium -R /app USER libmedium -ENTRYPOINT ["/usr/local/bin/libmedium"] +ENTRYPOINT ["/app/libmedium"] diff --git a/build.rs b/build.rs index 5099983..3ad9ccb 100644 --- a/build.rs +++ b/build.rs @@ -23,5 +23,5 @@ fn main() { .expect("error in git command, is git installed?"); let git_hash = String::from_utf8(output.stdout).unwrap(); println!("cargo:rustc-env=GIT_HASH={}", git_hash); - println!("cargo:rerun-if-changed=src/schema2.graphql,templates/main.css"); + println!("cargo:rerun-if-changed=src/schema2.graphql,static/main.css"); } diff --git a/config.toml b/config.toml index 9d39b27..cf5eeb9 100644 --- a/config.toml +++ b/config.toml @@ -1,5 +1,5 @@ debug = true -#cache = "/var/lib/libmedium" +#cache = "/cache" port = 7000 ip= "0.0.0.0" domain = "example.com" diff --git a/src/main.rs b/src/main.rs index e899e9f..00bb994 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,6 +20,7 @@ use actix_web::{ error::InternalError, http::StatusCode, middleware as actix_middleware, web::JsonConfig, App, HttpServer, }; +use actix_files as fs; use lazy_static::lazy_static; use log::info; @@ -66,6 +67,7 @@ async fn main() -> std::io::Result<()> { HttpServer::new(move || { App::new() + .service(fs::Files::new("/static", "./static")) .wrap(actix_middleware::Logger::default()) .wrap(actix_middleware::Compress::default()) .app_data(get_json_err()) diff --git a/src/settings.rs b/src/settings.rs index 16a4ba7..f2768f4 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -40,16 +40,10 @@ impl Settings { let mut s = Config::builder(); // setting default values - const CURRENT_DIR: &str = "./config.toml"; - const ETC: &str = "/etc/libmedium/config.toml"; - if let Ok(path) = env::var("LIBMEDIUM") { s = s.add_source(File::with_name(&path)); - } else if Path::new(CURRENT_DIR).exists() { - // merging default config from file - s = s.add_source(File::with_name(CURRENT_DIR)); - } else if Path::new(ETC).exists() { - s = s.add_source(File::with_name(ETC)); + } else if Path::new("./config.toml").exists() { + s = s.add_source(File::with_name("./config.toml"); } else { log::warn!("configuration file not found"); } diff --git a/templates/main.css b/static/main.css similarity index 100% rename from templates/main.css rename to static/main.css diff --git a/templates/index.html b/templates/index.html index 59d1dac..b312187 100644 --- a/templates/index.html +++ b/templates/index.html @@ -3,6 +3,7 @@ + LibMedium @@ -30,7 +31,4 @@ - diff --git a/templates/post.html b/templates/post.html index 89e5715..9c9c91a 100644 --- a/templates/post.html +++ b/templates/post.html @@ -29,7 +29,4 @@ - diff --git a/templates/post_meta.html b/templates/post_meta.html index 8283f1f..7f1bd3c 100644 --- a/templates/post_meta.html +++ b/templates/post_meta.html @@ -74,3 +74,4 @@ rel="canonical" href="http://<.= &*crate::SETTINGS.domain .>/<.= data.creator.name .>/<.= data.unique_slug .>" /> +