# Stage 1: Build the app
FROM node:22-alpine AS builder
WORKDIR /app

COPY package*.json ./
RUN npm install

COPY . .

# This automatically sets the environment to production for the build  (meta.env.MODE = 'production')
# so that the placeholders in the code are replaced with the actual API URLs
RUN npm run build

# Stage 2: Serve the app with Nginx
FROM nginx:alpine
# Remove the default Nginx static assets
RUN rm -rf /usr/share/nginx/html/*
# Copy the production build into the 'claim' folder
RUN mkdir -p /usr/share/nginx/html/claim
COPY --from=builder /app/dist/ /usr/share/nginx/html/claim
# Copy the custom Nginx configuration file
COPY nginx.conf /etc/nginx/conf.d/default.conf
# Copy and make executable the entrypoint script
COPY entrypoint.sh /entrypoint.sh
RUN sed -i 's/\r$//' /entrypoint.sh && chmod +x /entrypoint.sh

EXPOSE 80
ENTRYPOINT ["/entrypoint.sh"]
CMD ["nginx", "-g", "daemon off;"]
