# Stage 1: Build the app
FROM node:22-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build

# Stage 2: Serve with nginx
FROM nginx:alpine
COPY --from=build /app/dist /usr/share/nginx/html
COPY nginx.conf.template /etc/nginx/nginx.conf.template
COPY nginx.http.conf.template /etc/nginx/nginx.http.conf.template
COPY docker/start-nginx.sh /docker/start-nginx.sh
RUN chmod +x /docker/start-nginx.sh

EXPOSE 80
EXPOSE 443

# Set default runtime values (can be overridden at runtime)
ENV BACKEND_HOST=chore-app-backend
ENV FRONTEND_SSL_ENABLED=true

CMD ["/docker/start-nginx.sh"]
