# Stage 1: Build
FROM node:20-bullseye AS builder
WORKDIR /app

# Copy package files and install dependencies
COPY package.json package-lock.json ./
RUN npm install

# Copy the rest of the source code
COPY . .

# Set environment variable for Vite
ENV VITE_API_BASE_URL=https://midastix.com/api

# Fix permissions for all node_modules binaries and build
RUN chmod -R +x node_modules/.bin/ && \
    npm run build

# Stage 2: Serve with Node
FROM node:20-bullseye
WORKDIR /app

RUN npm install -g serve

# Copy build output from builder
COPY --from=builder /app/dist build

EXPOSE 3000
CMD ["serve", "-s", ".", "-l", "3000"]