# Stage 1: Build the frontend
FROM node:20-alpine AS client-builder
WORKDIR /app/client
COPY client/package*.json ./
RUN npm install
COPY client/ ./
RUN npm run build

# Stage 2: Setup the backend
FROM node:20-alpine
WORKDIR /app
COPY server/package*.json ./server/
RUN cd server && npm install --production
COPY server/ ./server/
COPY --from=client-builder /app/client/dist ./client/dist

# Create database directory if it doesn't exist
RUN mkdir -p /app/server/database

# Expose port
EXPOSE 3001

# Command to run the app
CMD ["node", "server/index.js"]
