From 458a75a740db0fb5ee9905a467260b7c8beaa8b7 Mon Sep 17 00:00:00 2001 From: pguerrerox Date: Tue, 26 May 2026 23:44:23 +0000 Subject: [PATCH] fix: proxy web /api routes to api container --- Dockerfile | 1 + README.md | 2 +- nginx.default.conf | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 nginx.default.conf diff --git a/Dockerfile b/Dockerfile index b9e9836..c6e3440 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,6 +15,7 @@ RUN npm run build && npm run build:api FROM nginx:alpine AS web COPY --from=build /app/dist /usr/share/nginx/html +COPY nginx.default.conf /etc/nginx/conf.d/default.conf FROM node:22-alpine AS runtime-base WORKDIR /app diff --git a/README.md b/README.md index c119483..bbb9b8f 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ Notes: - `APP_PORT` - `COOKIE_SECRET` - `GOOGLE_MAPS_SERVER_KEY` - - `VITE_API_BASE_URL` + - `VITE_API_BASE_URL` (use `/api` when web and API share a domain via the nginx proxy) - `VITE_GOOGLE_MAPS_PLATFORM_KEY` 2. Create the shared Docker network if it does not exist: `docker network create locale-all || true` diff --git a/nginx.default.conf b/nginx.default.conf new file mode 100644 index 0000000..ea1ba92 --- /dev/null +++ b/nginx.default.conf @@ -0,0 +1,20 @@ +server { + listen 80; + server_name _; + + root /usr/share/nginx/html; + index index.html; + + location /api/ { + proxy_pass http://api:4000; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + location / { + try_files $uri /index.html; + } +}