npm run build:ssr npm run serve:ssr
FROM node:latest AS build WORKDIR /app COPY package*.json ./ RUN npm install COPY . . RUN npm run build:ssr
FROM nginx:latest COPY --from=build /app/dist/ /usr/share/nginx/html/
server { listen 80; server_name example.com;
root /usr/share/nginx/html;
index index.html;
# redirect all http traffic to https
if ($scheme != "https") {
return 301 https://$server_name$request_uri;
}
# serve static content
location / {
try_files $uri $uri/ =404;
}
# serve SSR content
location /api {
proxy_pass http://backend:3000;
}
# SSR rendering
location / {
try_files $uri @ssr;
}
location @ssr {
# enable SSR
proxy_pass http://backend:4000;
# set headers to tell the server that it's a SSR request
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Url-Scheme $scheme;
# enable WebSocket communication
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
version: "3" services: frontend: container_name: frontend build: context: . dockerfile: Docker