# Use Node.js 18.16.0 as the base image
FROM node:18.16.0-alpine

# Set the working directory in the container
WORKDIR /usr/src/app

# Copy package.json and package-lock.json (if it exists) for the server
COPY server/package*.json ./

# Install production dependencies
RUN npm install --only=production

# Copy the server files
COPY server ./server

# Copy the pre-built dist folder from the app directory
COPY app/dist ./dist

# Create an empty rate-limit-data.json file
RUN echo '{}' > rate-limit-data.json && chmod 644 rate-limit-data.json

# Expose the port the app runs on
EXPOSE ${PORT}

# Start the server
CMD ["node", "server/server.js"]
