server libraries locally in the docker container

This commit is contained in:
kaysond 2021-11-28 09:42:59 -08:00 committed by nitnelave
parent ddeb4c3ce3
commit 9f138ec4ac
7 changed files with 69 additions and 13 deletions

View File

@ -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

View File

@ -23,7 +23,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css2?family=Bebas+Neue&display=swap" rel="stylesheet">
<link rel="stylesheet" href="/style.css">
<link rel="stylesheet" href="/static/style.css">
</head>
<body>

32
app/index_local.html Normal file
View File

@ -0,0 +1,32 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>LLDAP Administration</title>
<script src="/pkg/bundle.js" defer></script>
<link
href="/static/bootstrap.min.css"
rel="preload stylesheet"
integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x"
crossorigin="anonymous"
as="style" />
<script
src="bootstrap.bundle.min.js"
integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ"
crossorigin="anonymous"></script>
<link
rel="stylesheet"
href="/static/bootstrap-icons.css"
as="style" />
<link rel="stylesheet" href="/static/font-awesome.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/static/fonts.css" rel="stylesheet">
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
</body>
</html>

18
app/static/fonts.css Normal file
View File

@ -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;
}

6
app/static/libraries.txt Normal file
View File

@ -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

View File

@ -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<NamedFile> {
async fn index() -> actix_web::Result<NamedFile> {
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<Backend>(
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::<Backend>))
// API endpoint.
.service(
@ -76,8 +70,12 @@ fn http_config<Backend>(
)
// 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<Backend> {