Add Docker and Nginx config for frontend, backend, and MongoDB

This commit is contained in:
Francesco Lorenzo D'Amico
2026-03-19 11:27:14 +01:00
parent c983b6c42f
commit d525e8476d
6 changed files with 142 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
node_modules
dist
npm-debug.log
.env
+23
View File
@@ -0,0 +1,23 @@
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
ARG VITE_API_URL=""
ENV VITE_API_URL=$VITE_API_URL
RUN npm run build
FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
+37
View File
@@ -0,0 +1,37 @@
server {
listen 80;
# Serve the static React build
location / {
root /usr/share/nginx/html;
index index.html;
# Fallback to index.html for client-side routing
try_files $uri $uri/ /index.html;
}
# Proxy REST API requests to the backend
location /rooms {
proxy_pass http://backend: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 the health check endpoint to the backend
location /health {
proxy_pass http://backend:4000;
proxy_http_version 1.1;
}
# Proxy Socket.IO — requires WebSocket upgrade headers
location /socket.io/ {
proxy_pass http://backend:4000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_cache_bypass $http_upgrade;
}
}