feat(docker, nginx): optimize Dockerfile for frontend build and enhance demo server configuration with mock files and improved WebSocket feedback
This commit is contained in:
@@ -8,7 +8,9 @@ FROM node:${NODE_VERSION}-alpine@${NODE_ALPINE_SHA256} AS build-frontend
|
||||
WORKDIR /src
|
||||
|
||||
COPY package.json vite.config.js pnpm-lock.yaml tailwind.config.js postcss.config.js ./
|
||||
COPY meshchatx ./meshchatx
|
||||
# Copy only the frontend source and version info to speed up builds and reduce image size
|
||||
COPY meshchatx/src/frontend ./meshchatx/src/frontend
|
||||
COPY meshchatx/src/version.py ./meshchatx/src/version.py
|
||||
|
||||
RUN corepack enable && corepack prepare pnpm@latest --activate
|
||||
|
||||
|
||||
@@ -24,10 +24,29 @@ server {
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
# Handle manifest.json and service-worker.js specifically
|
||||
location ~* (manifest\.json|service-worker\.js) {
|
||||
# Mocking missing critical files for demo stability
|
||||
location = /manifest.json {
|
||||
add_header Cache-Control "no-cache";
|
||||
try_files $uri =404;
|
||||
add_header Content-Type application/json;
|
||||
try_files $uri @mock_manifest;
|
||||
}
|
||||
location @mock_manifest {
|
||||
return 200 '{"name": "MeshChat Demo", "short_name": "MeshChat", "start_url": "/", "display": "standalone", "icons": [{"src": "/favicons/favicon-512x512.png", "sizes": "512x512", "type": "image/png"}]}';
|
||||
}
|
||||
|
||||
location = /service-worker.js {
|
||||
add_header Cache-Control "no-cache";
|
||||
add_header Content-Type application/javascript;
|
||||
try_files $uri @mock_sw;
|
||||
}
|
||||
location @mock_sw {
|
||||
return 200 '// Mock Service Worker\nself.addEventListener("fetch", (event) => {});';
|
||||
}
|
||||
|
||||
# Mock Codec2 scripts to prevent load failures in demo mode
|
||||
location ^~ /assets/js/codec2-emscripten/ {
|
||||
add_header Content-Type application/javascript;
|
||||
try_files $uri =200;
|
||||
}
|
||||
|
||||
# Gzip compression
|
||||
@@ -215,6 +234,7 @@ server {
|
||||
add_header Content-Type application/json;
|
||||
}
|
||||
|
||||
# Improved WebSocket handler
|
||||
location /ws {
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
@@ -224,8 +244,12 @@ server {
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
|
||||
# In demo mode, there is no WebSocket backend service.
|
||||
# This block is configured to support WSS upgrades from a reverse proxy.
|
||||
# In demo mode, returning 200 for non-WS requests provides better feedback
|
||||
if ($http_upgrade != "websocket") {
|
||||
return 200 "WebSocket Mock Endpoint (Active)";
|
||||
}
|
||||
|
||||
# For actual WS connection attempts, we still return 503 as there is no backend server.
|
||||
return 503;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user