diff --git a/Dockerfile b/Dockerfile index 30f179c..ee30b65 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ # Multi-stage build for optimized production image # ============================================ -# Stage 1: Build +# Stage 1: Build Frontend # ============================================ FROM node:20-alpine AS builder @@ -11,8 +11,14 @@ WORKDIR /app # Copy package files COPY package*.json ./ -# Install dependencies -RUN npm install --omit=dev +# Install ALL dependencies (including devDependencies for Vite) +RUN npm install + +# Copy source files +COPY . . + +# Build the React app with Vite +RUN npm run build # ============================================ # Stage 2: Production @@ -29,12 +35,18 @@ RUN addgroup -g 1001 -S nodejs && \ WORKDIR /app -# Copy node_modules from builder -COPY --from=builder /app/node_modules ./node_modules - -# Copy application files +# Copy package files and install production deps only COPY package*.json ./ +RUN npm install --omit=dev + +# Copy server files COPY server.js ./ +COPY config.js ./ + +# Copy built frontend from builder stage +COPY --from=builder /app/dist ./dist + +# Copy public folder (for monolithic fallback reference) COPY public ./public # Set ownership diff --git a/server.js b/server.js index 39bac10..59516f3 100644 --- a/server.js +++ b/server.js @@ -41,8 +41,16 @@ if (ITURHFPROP_URL) { app.use(cors()); app.use(express.json()); -// Serve static files from public directory -app.use(express.static(path.join(__dirname, 'public'))); +// Serve static files - use 'dist' in production (Vite build), 'public' in development +const staticDir = process.env.NODE_ENV === 'production' + ? path.join(__dirname, 'dist') + : path.join(__dirname, 'public'); +app.use(express.static(staticDir)); + +// Also serve public folder for any additional assets +if (process.env.NODE_ENV === 'production') { + app.use(express.static(path.join(__dirname, 'public'))); +} // ============================================ // API PROXY ENDPOINTS @@ -2793,7 +2801,10 @@ app.get('/api/config', (req, res) => { // ============================================ app.get('*', (req, res) => { - res.sendFile(path.join(__dirname, 'public', 'index.html')); + const indexPath = process.env.NODE_ENV === 'production' + ? path.join(__dirname, 'dist', 'index.html') + : path.join(__dirname, 'public', 'index.html'); + res.sendFile(indexPath); }); // ============================================