FROM node:latest AS client-build
WORKDIR /usr/src/app
COPY client/ ./client/
RUN cd client && npm install && npm run build

FROM node:latest AS server-build
WORKDIR /usr/src/app
COPY server/ ./server/
RUN cd server && npm install && npm run build

FROM node:latest AS serve
WORKDIR /usr/src/app
COPY server/package*.json ./
RUN npm install --only=production
COPY --from=server-build /usr/src/app/server/dist ./distServer
COPY --from=client-build /usr/src/app/client/dist ./distClient
CMD ["node", "./distServer/app.js"]
