# Runtime only — frontend built externally via pnpm
FROM nginx:alpine

# Copy pre-built SPA assets (pnpm build outputs to dist/)
COPY dist /usr/share/nginx/html

# nginx configuration for SPA
RUN echo 'resolver 10.96.0.10 valid=10s ipv6=off; \
server { \
    listen 80; \
    server_name _; \
    root /usr/share/nginx/html; \
    index index.html; \
    location / { \
        try_files $uri $uri/ /index.html; \
    } \
    location /api/ { \
        set $upstream_app http://app:8080; \
        proxy_pass $upstream_app/api/; \
        proxy_set_header Host $host; \
        proxy_set_header X-Real-IP $remote_addr; \
    } \
    location /ws/ { \
        set $upstream_app http://app:8080; \
        proxy_pass $upstream_app/ws/; \
        proxy_http_version 1.1; \
        proxy_set_header Upgrade $http_upgrade; \
        proxy_set_header Connection "upgrade"; \
        proxy_set_header Host $host; \
    } \
}' > /etc/nginx/conf.d/default.conf

EXPOSE 80
ENTRYPOINT ["nginx", "-g", "daemon off;"]
