fix: serve frontend via root + slug subdir, not alias — assets 404/fallback
nginx alias + try_files resolves paths incorrectly (nginx trac #97), so asset requests fell through to the SPA fallback and index.html was served as the JS bundle — the app never booted. Match the proven twin-optimiser pattern: copy dist to html/room-planner and use root with try_files. Also node:20 → node:22 per stack convention. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
5a2dab637c
commit
a7cc79a9b1
2 changed files with 20 additions and 7 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
FROM node:20-alpine AS build
|
FROM node:22-alpine AS build
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY package.json .
|
COPY package.json .
|
||||||
RUN npm install
|
RUN npm install
|
||||||
|
|
@ -8,6 +8,6 @@ ENV VITE_HOTEL_NAME=$VITE_HOTEL_NAME
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
FROM nginx:alpine
|
FROM nginx:alpine
|
||||||
COPY --from=build /app/dist /usr/share/nginx/html
|
COPY --from=build /app/dist /usr/share/nginx/html/room-planner
|
||||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,7 @@
|
||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
|
server_name localhost;
|
||||||
location /room-planner/ {
|
root /usr/share/nginx/html;
|
||||||
alias /usr/share/nginx/html/;
|
|
||||||
try_files $uri $uri/ /room-planner/index.html;
|
|
||||||
}
|
|
||||||
|
|
||||||
location /room-planner/api/auth/ {
|
location /room-planner/api/auth/ {
|
||||||
proxy_pass http://10.10.10.101:3001/api/auth/;
|
proxy_pass http://10.10.10.101:3001/api/auth/;
|
||||||
|
|
@ -18,6 +15,7 @@ server {
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
add_header Cache-Control "no-store";
|
||||||
# SSE support
|
# SSE support
|
||||||
proxy_buffering off;
|
proxy_buffering off;
|
||||||
proxy_cache off;
|
proxy_cache off;
|
||||||
|
|
@ -27,4 +25,19 @@ server {
|
||||||
location /room-planner/health {
|
location /room-planner/health {
|
||||||
proxy_pass http://backend:3001/health;
|
proxy_pass http://backend:3001/health;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
location ~* /room-planner/.*\.(js|css|png|ico|svg|woff2?)$ {
|
||||||
|
expires 1y;
|
||||||
|
add_header Cache-Control "public, immutable";
|
||||||
|
try_files $uri =404;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /room-planner/ {
|
||||||
|
add_header Cache-Control "no-cache" always;
|
||||||
|
try_files $uri $uri/ /room-planner/index.html;
|
||||||
|
}
|
||||||
|
|
||||||
|
location = / {
|
||||||
|
return 301 /room-planner/;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue