all repos — stealth-developers @ b30621f89da1d2cbca3735c0662931f8f0608758

feat(server): serve frontend
vi did:web:vt3e.cat
Sat, 09 May 2026 01:37:22 +0100
commit

b30621f89da1d2cbca3735c0662931f8f0608758

parent

7a84b741bc2c10def09e4d5e05151d8224e8220d

1 files changed, 21 insertions(+), 8 deletions(-)

jump to
M src/server/index.tssrc/server/index.ts

@@ -33,7 +33,7 @@ const server = Bun.serve({

hostname: "127.0.0.1", routes: { - "/login": () => { + "/api/login": () => { const redirectUri = `https://discord.com/oauth2/authorize?client_id=${CLIENT_ID}&response_type=code&redirect_uri=${encodeURIComponent(REDIRECT_URI)}&scope=identify+guilds`; return new Response(null, {

@@ -43,7 +43,7 @@ Location: redirectUri,

}, }); }, - "/auth/callback": { + "/api/auth/callback": { GET: async (req) => { const url = new URL(req.url); const code = url.searchParams.get("code");

@@ -94,7 +94,7 @@ },

}); }, }, - "/me": { + "/api/me": { GET: async (req: BunRequest) => { const user = await getSessionUser(req); if (!user) return new Response("Unauthorized", { status: 401 });

@@ -113,7 +113,7 @@ headers: { "Content-Type": "application/json" },

}); }, }, - "/tickets": { + "/api/tickets": { GET: async (req: BunRequest) => { const user = await getSessionUser(req); if (!user) return new Response(null, { status: 302, headers: { Location: "/login" } });

@@ -146,7 +146,7 @@ headers: { "Content-Type": "application/json" },

}); }, }, - "/tickets/:id": { + "/api/tickets/:id": { GET: async (req: BunRequest) => { const user = await getSessionUser(req); if (!user) return new Response(null, { status: 302, headers: { Location: "/login" } });

@@ -269,7 +269,7 @@ headers: { "Content-Type": "application/json" },

}); }, }, - "/moderators": { + "/api/moderators": { GET: async (req: BunRequest) => { const user = await getSessionUser(req); if (!user) return new Response("Unauthorized", { status: 401 });

@@ -298,7 +298,7 @@ headers: { "Content-Type": "application/json" },

}); }, }, - "/stats/overall": { + "/api/stats/overall": { GET: async (req: BunRequest) => { const user = await getSessionUser(req); if (!user) return new Response("Unauthorized", { status: 401 });

@@ -367,7 +367,7 @@ headers: { "Content-Type": "application/json" },

}); }, }, - "/stats/leaderboard": { + "/api/stats/leaderboard": { GET: async (req: BunRequest) => { const user = await getSessionUser(req); if (!user) return new Response("Unauthorized", { status: 401 });

@@ -446,6 +446,19 @@ return new Response(JSON.stringify(leaderboard), {

headers: { "Content-Type": "application/json" }, }); }, + }, + "/api/*": () => { + return new Response(null, { status: 404 }); + }, + + "/*": async (request) => { + const { pathname } = new URL(request.url); + + const file = Bun.file(`frontend/dist/${pathname}`); + if (await file.exists()) return new Response(file, { status: 200 }); + + const indexFile = Bun.file(`frontend/dist/index.html`); + return new Response(indexFile, { status: 200 }); }, }, });