# Use a Node.js base image for building the application
FROM node:current-slim AS build

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

# Copy package.json and package-lock.json
COPY package*.json ./

# Install dependencies
RUN npm install

# Copy the rest of the application code
COPY . .

# Build the application
RUN npm run build

# Use a Caddy base image for serving the application
FROM caddy:latest

# Set the working directory
WORKDIR /usr/share/caddy

# Copy the built application from the previous stage
COPY --from=build /usr/src/app/dist .

# Expose the port
EXPOSE 3131

# Copy the Caddyfile into the image
COPY Caddyfile /etc/caddy/Caddyfile

# CMD instruction is not needed as Caddy will be started automatically by the base image