FROM node:20-alpine AS builder

WORKDIR /app

COPY package*.json ./

RUN npm install

COPY . .

RUN npm run build

FROM node:20-alpine

WORKDIR /app

COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/proxy-server.js ./

RUN npm install express cors http-proxy-middleware

RUN apk add --no-cache nginx

COPY nginx.conf /etc/nginx/conf.d/default.conf

COPY start.sh /start.sh

RUN chmod +x /start.sh

EXPOSE 80 3000

CMD ["/start.sh"]
