FROM node:20-alpine AS builder

WORKDIR /app

COPY admin-web/town-editor/package.json admin-web/town-editor/
RUN cd admin-web/town-editor && npm install

COPY admin-web/town-editor admin-web/town-editor
COPY frontend/src frontend/src
COPY frontend/assets frontend/assets
COPY frontend/public frontend/public

RUN cd admin-web/town-editor && npm run build

FROM nginx:alpine

RUN rm /etc/nginx/conf.d/default.conf
COPY admin-web/nginx.conf /etc/nginx/conf.d/default.conf
COPY admin-web/index.html /usr/share/nginx/html/index.html
COPY --from=builder /app/admin-web/town-editor/dist /usr/share/nginx/html/town-editor

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
