diff --git a/Dockerfile b/Dockerfile index 0e7af90a..433b5bae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,8 +13,8 @@ RUN if [ -f pnpm-lock.yaml ]; then npm install -g pnpm && pnpm install --frozen- # Copy source code COPY . . -# Build the app (frontend + server) -# RUN npm run build +# Build the client so the Activity gets compiled JS (no Vite dev mode in Discord iframe) +RUN npm run build:client # Set environment ENV NODE_ENV=production diff --git a/server/index.ts b/server/index.ts index 99d20d9e..047f4f19 100644 --- a/server/index.ts +++ b/server/index.ts @@ -2,6 +2,7 @@ import "dotenv/config"; import "dotenv/config"; import express from "express"; import cors from "cors"; +import path from "path"; import { adminSupabase } from "./supabase"; import { emailService } from "./email"; import { randomUUID, createHash, createVerify, randomBytes, createHmac } from "crypto"; @@ -8192,5 +8193,17 @@ export function createServer() { return manageSubscriptionHandler(req as any, res as any); }); + // Serve compiled SPA static assets (built by `npm run build:client`) + const spaDir = path.join(process.cwd(), "dist/spa"); + app.use(express.static(spaDir, { index: false })); + + // SPA catch-all — serve index.html for all non-API routes + app.get("*", (req: express.Request, res: express.Response) => { + if (req.path.startsWith("/api/")) { + return res.status(404).json({ error: "API endpoint not found" }); + } + res.sendFile(path.join(spaDir, "index.html")); + }); + return app; }