FROM node:20.19-slim

WORKDIR /app

# Copy application dependency manifests to the container image.
# A wildcard is used to ensure both package.json AND package-lock.json are copied.
# Copying this first prevents re-running npm install on every code change.
COPY package*.json ./

# Install dependencies
RUN yarn install --registry https://registry.npmmirror.com/ --ignore-engines

# Copy the rest of the application files to the container image.
COPY . .

# Build the application
RUN yarn run build

RUN echo "Debug: Contents of /app after build:"
RUN ls -la /app
RUN echo "Debug: Contents of /app/dist after build:"
RUN ls -la /app/dist || echo "Debug: /app/dist directory not found or ls failed"

EXPOSE 3302

CMD ["node", "--enable-source-maps", "--no-node-snapshot", "dist/index.js"]