From 74ea7e4d26a3ed290bc25a96ae3c611eb8986dd3 Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Thu, 7 May 2026 21:01:46 -0400 Subject: [PATCH] fix dist --- Containerfile | 1 + src/index.ts | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Containerfile b/Containerfile index 745c0d0..b834de1 100644 --- a/Containerfile +++ b/Containerfile @@ -3,6 +3,7 @@ WORKDIR /app COPY package.json bun.lock ./ RUN bun install --frozen-lockfile COPY . . +RUN bun run build ENV NODE_ENV=production EXPOSE 3000 CMD ["bun", "run", "src/index.ts"] diff --git a/src/index.ts b/src/index.ts index e9966d1..470104d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,10 @@ import { serve } from "bun"; -import index from "./index.html"; +import { join } from "path"; import { privateApps } from "./data/privateApps"; import { websites } from "./data/websites"; +const distDir = join(import.meta.dir, "..", "dist"); + let hnCache: { stories: any[]; fetchedAt: number } | null = null; let lobstersCache: { stories: any[]; fetchedAt: number } | null = null; @@ -112,8 +114,15 @@ const server = serve({ hostname: "0.0.0.0", port: 3000, routes: { - // Serve index.html for all unmatched routes. - "/*": index, + // Serve static assets from dist/, with index.html fallback for SPA routes. + "/*": async (req) => { + const url = new URL(req.url); + const candidate = Bun.file( + join(distDir, url.pathname === "/" ? "index.html" : url.pathname), + ); + if (await candidate.exists()) return new Response(candidate); + return new Response(Bun.file(join(distDir, "index.html"))); + }, "/api/check": { async POST(req) { -- 2.51.2