diff --git a/docker-compose.yml b/docker-compose.yml index 35f0d60..c59e0fc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,5 +27,13 @@ services: ports: - "8000:8000" + frontend: + build: ./frontend + restart: unless-stopped + depends_on: + - backend + ports: + - "8080:80" + volumes: pgdata: diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 0000000..a21f178 --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1,3 @@ +node_modules +dist +.git diff --git a/frontend/Dockerfile b/frontend/Dockerfile index fa42836..1836728 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,9 +1,11 @@ FROM node:22-slim AS build WORKDIR /app -COPY package.json . -RUN npm install +COPY package.json package-lock.json . +RUN npm ci COPY . . RUN npm run build -FROM scratch AS dist -COPY --from=build /app/dist / +FROM nginx:1.27-alpine +COPY --from=build /app/dist /usr/share/nginx/html +COPY nginx.conf /etc/nginx/conf.d/default.conf +EXPOSE 80 diff --git a/frontend/nginx.conf b/frontend/nginx.conf new file mode 100644 index 0000000..5bc2e80 --- /dev/null +++ b/frontend/nginx.conf @@ -0,0 +1,48 @@ +server { + listen 80; + server_name _; + + root /usr/share/nginx/html; + index index.html; + + # Same-origin as far as the browser is concerned — api/client.ts calls relative paths, so + # this proxies them to the backend container internally instead of relying on CORS. + location /api/ { + proxy_pass http://backend:8000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + + location /auth/ { + proxy_pass http://backend:8000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + + location /users/ { + proxy_pass http://backend:8000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + + location /health { + proxy_pass http://backend:8000; + } + + location /ws/ { + proxy_pass http://backend:8000; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_read_timeout 3600s; + } + + # SPA fallback — client-side routes (e.g. /games/) must resolve to index.html. + location / { + try_files $uri /index.html; + } +}