cleanup: route table, lobby rename, missing-file 404s

This commit is contained in:
DarthMooMancer committed 2026-11-01 23:18:08 -05:00
1 parent e688c2bdf1
commit 2c783e07ca
3 files changed
+30 -40

No files matched your search

+30 -10
View File
@@ -9,30 +9,50 @@ interface Player {
}
const rooms = new Map<string, { teacherWs: any; players: Map<any, Player> }>();
const pages: Record<string, string> = {
"/": "index.html",
"/host": "lobby.html",
"/lobby": "lobby.html",
"/waiting": "waiting.html",
"/game": "game.html",
"/trading": "trading.html",
"/ws-test": "ws-test.html",
};
const server = Bun.serve<WebSocketData>({
port: 3000,
fetch(req, server) {
async fetch(req, server) {
const url = new URL(req.url);
console.log(req.method, url.pathname);
// If the request if for a Websocket upgrade, let Bun handle it
//
if (url.pathname === "/ws") {
if (server.upgrade(req, { data: { role: "student", roomCode: "" } }))
return;
return new Response("WebSocket upgrade failed", { status: 400 });
}
if (url.pathname === "/") return new Response(Bun.file("index.html"));
if (url.pathname === "/waiting")
return new Response(Bun.file("waiting.html"));
if (url.pathname === "/game") return new Response(Bun.file("game.html"));
if (url.pathname === "/host") return new Response(Bun.file("host.html"));
const page = pages[url.pathname];
if (page) {
const file = Bun.file(page);
if (!(await file.exists())) {
return new Response("Not Found", { status: 404 });
}
return new Response(Bun.file(page));
}
if (
url.pathname.startsWith("/client/") ||
url.pathname.startsWith("/assets/")
) {
if (url.pathname.includes("..")) {
return new Response("Bad path", { status: 400 });
}
return new Response(Bun.file("." + url.pathname));
}
if (url.pathname === "/styles.css")
return new Response(Bun.file("styles.css"));
if (url.pathname === "/index.js") return new Response(Bun.file("index.js"));
if (url.pathname.startsWith("/assets/"))
return new Response(Bun.file("." + url.pathname));
if (url.pathname == "/api/health") {
return Response.json({ ok: true, time: Date.now() });
}
View File
File renamed without changes.
-30
View File
@@ -1,30 +0,0 @@
<!doctype html>
<html>
<head>
<title>Escape the Island</title>
<link rel="icon" type="image/x-icon" href="assets/shipwreck.png" />
<link rel="stylesheet" href="styles.css" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Almendra:ital,wght@0,400;0,700;1,400;1,700&display=swap"
rel="stylesheet"
/>
</head>
<body>
<header>
<div class="header-container">
<h1>Escape the Island</h1>
<div class="boat-container">
<img src="assets/boat.png" alt="" class="boat" />
</div>
</div>
</header>
<div class="Content"></div>
<footer>
<h3 style="padding: 10px 0px 0px 10px">
Gamemaker: Mr. J. Walla ~=~ Developer: Andrew H. ~=~ Designer: Logan C.
</h3>
</footer>
</body>
</html>