From 9f138ec4acb1ee5f92a47edb48a7232c2a8f7733 Mon Sep 17 00:00:00 2001 From: kaysond Date: Sun, 28 Nov 2021 09:42:59 -0800 Subject: [PATCH] server libraries locally in the docker container --- Dockerfile | 4 +++- app/index.html | 2 +- app/index_local.html | 32 ++++++++++++++++++++++++++++++++ app/static/fonts.css | 18 ++++++++++++++++++ app/static/libraries.txt | 6 ++++++ app/{ => static}/style.css | 0 server/src/infra/tcp_server.rs | 20 +++++++++----------- 7 files changed, 69 insertions(+), 13 deletions(-) create mode 100644 app/index_local.html create mode 100644 app/static/fonts.css create mode 100644 app/static/libraries.txt rename app/{ => static}/style.css (100%) diff --git a/Dockerfile b/Dockerfile index 08dc670..d96b0aa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -44,13 +44,15 @@ FROM alpine:3.14 WORKDIR /app -COPY --from=builder /app/app/index.html /app/app/main.js /app/app/style.css app/ +COPY --from=builder /app/app/index_local.html app/index.html +COPY --from=builder /app/app/static app/static COPY --from=builder /app/app/pkg app/pkg COPY --from=builder /app/target/release/lldap lldap COPY docker-entrypoint.sh lldap_config.docker_template.toml ./ RUN set -x \ && apk add --no-cache bash \ + && for file in $(cat app/static/libraries.txt); do wget -P app/static "$file"; done \ && chmod a+r -R . ENV LDAP_PORT=3890 diff --git a/app/index.html b/app/index.html index 5bcf44e..1b4d45a 100644 --- a/app/index.html +++ b/app/index.html @@ -23,7 +23,7 @@ - + diff --git a/app/index_local.html b/app/index_local.html new file mode 100644 index 0000000..d703efa --- /dev/null +++ b/app/index_local.html @@ -0,0 +1,32 @@ + + + + + + LLDAP Administration + + + + + + + + + + + + + + + diff --git a/app/static/fonts.css b/app/static/fonts.css new file mode 100644 index 0000000..27bb97c --- /dev/null +++ b/app/static/fonts.css @@ -0,0 +1,18 @@ +/* latin-ext */ +@font-face { + font-family: 'Bebas Neue'; + font-style: normal; + font-weight: 400; + font-display: swap; + src: url(JTUSjIg69CK48gW7PXoo9Wdhyzbi.woff2) format('woff2'); + unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF; +} +/* latin */ +@font-face { + font-family: 'Bebas Neue'; + font-style: normal; + font-weight: 400; + font-display: swap; + src: url(JTUSjIg69CK48gW7PXoo9Wlhyw.woff2) format('woff2'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} \ No newline at end of file diff --git a/app/static/libraries.txt b/app/static/libraries.txt new file mode 100644 index 0000000..fdb4b42 --- /dev/null +++ b/app/static/libraries.txt @@ -0,0 +1,6 @@ +https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css +https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/js/bootstrap.bundle.min.js +https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css +https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css +https://fonts.gstatic.com/s/bebasneue/v2/JTUSjIg69CK48gW7PXoo9Wdhyzbi.woff2 +https://fonts.gstatic.com/s/bebasneue/v2/JTUSjIg69CK48gW7PXoo9Wlhyw.woff2 \ No newline at end of file diff --git a/app/style.css b/app/static/style.css similarity index 100% rename from app/style.css rename to app/static/style.css diff --git a/server/src/infra/tcp_server.rs b/server/src/infra/tcp_server.rs index 36231f8..9d083ba 100644 --- a/server/src/infra/tcp_server.rs +++ b/server/src/infra/tcp_server.rs @@ -14,7 +14,7 @@ use actix_files::{Files, NamedFile}; use actix_http::HttpServiceBuilder; use actix_server::ServerBuilder; use actix_service::map_config; -use actix_web::{dev::AppConfig, web, App, HttpRequest, HttpResponse}; +use actix_web::{dev::AppConfig, web, App, HttpResponse}; use anyhow::{Context, Result}; use hmac::{Hmac, NewMac}; use sha2::Sha512; @@ -22,11 +22,10 @@ use std::collections::HashSet; use std::path::PathBuf; use std::sync::RwLock; -async fn index(req: HttpRequest) -> actix_web::Result { +async fn index() -> actix_web::Result { let mut path = PathBuf::new(); path.push("app"); - let file = req.match_info().query("filename"); - path.push(if file.is_empty() { "index.html" } else { file }); + path.push("index.html"); Ok(NamedFile::open(path)?) } @@ -62,11 +61,6 @@ fn http_config( server_url, mail_options, })) - // Serve index.html and main.js, and default to index.html. - .route( - "/{filename:(index\\.html|main\\.js|style\\.css)?}", - web::get().to(index), - ) .service(web::scope("/auth").configure(auth_service::configure_server::)) // API endpoint. .service( @@ -76,8 +70,12 @@ fn http_config( ) // Serve the /pkg path with the compiled WASM app. .service(Files::new("/pkg", "./app/pkg")) - // Default to serve index.html for unknown routes, to support routing. - .service(web::scope("/").route("/.*", web::get().to(index))); + // Serve static files + .service(Files::new("/static", "./app/static")) + // Serve the index + .service(web::scope("/") + .route("", web::get().to(index)) + .route("index.html", web::get().to(index))); } pub(crate) struct AppState {