FROM nginx:1.27-alpine AS production

# Remove default nginx config
RUN rm /etc/nginx/conf.d/default.conf

# Copy nginx config from project root
COPY default.conf /etc/nginx/conf.d/default.conf

# Copy web files (index.html + assets)
COPY index.html /usr/share/nginx/html/index.html
COPY site.webmanifest /usr/share/nginx/html/site.webmanifest
COPY assets/ /usr/share/nginx/html/assets/

# Generate config.js from env vars at container start
COPY generate-config.sh /docker-entrypoint.d/99-generate-config.sh
RUN chmod +x /docker-entrypoint.d/99-generate-config.sh

EXPOSE 80

HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
    CMD wget -qO- http://localhost:80/ || exit 1
