Feat: Web loader

This commit is contained in:
MangoPig
2026-06-15 06:59:57 +01:00
parent 90de5ca868
commit 99538e30c8
14 changed files with 559 additions and 3 deletions

View File

@@ -1,5 +1,10 @@
# syntax=docker/dockerfile:1.7
## Frontend
## =========================
ARG NGINX_VERSION=1.29.8
FROM node:22-alpine AS frontend-dependencies
WORKDIR /workspace/Frontend
@@ -17,10 +22,77 @@ COPY Frontend/ ./
RUN pnpm build:static
FROM nginx:1.29-alpine AS production
## Proxy
## =========================
FROM alpine:3.22 AS precompressed-assets
RUN apk add --no-cache brotli gzip
WORKDIR /workspace
COPY Loader ./html/__loader
COPY --from=frontend-build /workspace/Frontend/dist/client ./html
RUN find ./html -type f \( \
-name '*.html' -o \
-name '*.css' -o \
-name '*.js' -o \
-name '*.json' -o \
-name '*.svg' -o \
-name '*.txt' -o \
-name '*.xml' -o \
-name '*.webmanifest' \
\) -exec gzip -kf -9 {} \; \
&& find ./html -type f \( \
-name '*.html' -o \
-name '*.css' -o \
-name '*.js' -o \
-name '*.json' -o \
-name '*.svg' -o \
-name '*.txt' -o \
-name '*.xml' -o \
-name '*.webmanifest' \
\) -exec brotli -kf -Z {} \;
FROM alpine:3.22 AS brotli-modules
ARG NGINX_VERSION
RUN apk add --no-cache \
alpine-sdk \
cmake \
git \
linux-headers \
openssl-dev \
pcre2-dev \
wget \
zlib-dev
WORKDIR /tmp
RUN wget -O "nginx-${NGINX_VERSION}.tar.gz" "https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz" \
&& tar -xzf "nginx-${NGINX_VERSION}.tar.gz" \
&& git clone --recurse-submodules https://github.com/google/ngx_brotli.git
WORKDIR /tmp/nginx-${NGINX_VERSION}
RUN cd /tmp/ngx_brotli/deps/brotli \
&& mkdir -p out \
&& cd out \
&& cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS="-fPIC" -DCMAKE_CXX_FLAGS="-fPIC" .. \
&& cmake --build . --config Release -j"$(getconf _NPROCESSORS_ONLN)" \
&& cd /tmp/nginx-${NGINX_VERSION} \
&& ./configure --with-compat --add-dynamic-module=/tmp/ngx_brotli \
&& make modules
FROM nginx:${NGINX_VERSION}-alpine AS production
COPY Proxy/Local/nginx.conf /etc/nginx/nginx.conf
COPY Proxy/Local/default.conf /etc/nginx/conf.d/default.conf
COPY --from=frontend-build /workspace/Frontend/dist/client /usr/share/nginx/html
COPY --from=brotli-modules /tmp/nginx-${NGINX_VERSION}/objs/ngx_http_brotli_filter_module.so /usr/lib/nginx/modules/
COPY --from=brotli-modules /tmp/nginx-${NGINX_VERSION}/objs/ngx_http_brotli_static_module.so /usr/lib/nginx/modules/
COPY --from=precompressed-assets /workspace/html /usr/share/nginx/html
EXPOSE 80

View File

@@ -1,3 +1,8 @@
map $http_cookie $moku_bootstrap_document {
default /__loader/index.html;
"~*(^|; )moku_loader_seen=1($|;)" /index.html;
}
server {
listen 80;
server_name _;
@@ -5,8 +10,19 @@ server {
root /usr/share/nginx/html;
index index.html;
location = / {
add_header Cache-Control "no-store";
rewrite ^ $moku_bootstrap_document last;
}
location ^~ /__loader/ {
access_log off;
add_header Cache-Control "no-store";
try_files $uri =404;
}
location / {
try_files $uri $uri/ /index.html;
try_files $uri $uri/ $moku_bootstrap_document;
}
location /favicon.ico {

60
Proxy/Local/nginx.conf Normal file
View File

@@ -0,0 +1,60 @@
load_module /usr/lib/nginx/modules/ngx_http_brotli_filter_module.so;
load_module /usr/lib/nginx/modules/ngx_http_brotli_static_module.so;
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_static on;
gzip_vary on;
gzip_proxied any;
gzip_min_length 1024;
gzip_comp_level 6;
gzip_types
text/plain
text/css
text/javascript
application/javascript
application/json
application/manifest+json
application/xml
application/rss+xml
image/svg+xml;
brotli on;
brotli_static on;
brotli_comp_level 5;
brotli_min_length 1024;
brotli_types
text/plain
text/css
text/javascript
application/javascript
application/json
application/manifest+json
application/xml
application/rss+xml
image/svg+xml;
include /etc/nginx/conf.d/*.conf;
}