version 2
This commit is contained in:
@@ -6,38 +6,19 @@ const HTML = readFileSync("./src/public/index.html", "utf-8");
|
||||
const server = Bun.serve({
|
||||
port: 3000,
|
||||
fetch(req, server) {
|
||||
const url = new URL(req.url);
|
||||
|
||||
if (url.pathname === "/ws") {
|
||||
const ok = server.upgrade(req);
|
||||
if (!ok) return new Response("WebSocket upgrade failed", { status: 400 });
|
||||
if (new URL(req.url).pathname === "/ws") {
|
||||
if (!server.upgrade(req)) return new Response("WS upgrade failed", { status: 400 });
|
||||
return undefined as any;
|
||||
}
|
||||
|
||||
return new Response(HTML, {
|
||||
headers: { "Content-Type": "text/html; charset=utf-8" },
|
||||
});
|
||||
return new Response(HTML, { headers: { "Content-Type": "text/html; charset=utf-8" } });
|
||||
},
|
||||
websocket: {
|
||||
perMessageDeflate: true,
|
||||
maxPayloadLength: 64 * 1024,
|
||||
message(ws, msg) {
|
||||
if (typeof msg !== "string") return;
|
||||
handleMessage(ws, msg);
|
||||
},
|
||||
close(ws) {
|
||||
handleClose(ws);
|
||||
},
|
||||
maxPayloadLength: 32 * 1024,
|
||||
message(ws, msg) { if (typeof msg === "string") handleMessage(ws, msg); },
|
||||
close(ws) { handleClose(ws); },
|
||||
open(_ws) {},
|
||||
},
|
||||
});
|
||||
|
||||
console.log(`\x1b[32m ██████╗ ██╗ ██╗███████╗███████╗███████╗██████╗ \x1b[0m`);
|
||||
console.log(`\x1b[32m ██╔══██╗██║ ██║╚══███╔╝╚══███╔╝██╔════╝██╔══██╗\x1b[0m`);
|
||||
console.log(`\x1b[32m ██████╔╝██║ ██║ ███╔╝ ███╔╝ █████╗ ██████╔╝\x1b[0m`);
|
||||
console.log(`\x1b[32m ██╔══██╗██║ ██║ ███╔╝ ███╔╝ ██╔══╝ ██╔══██╗\x1b[0m`);
|
||||
console.log(`\x1b[32m ██████╔╝╚██████╔╝███████╗███████╗███████╗██║ ██║\x1b[0m`);
|
||||
console.log(`\x1b[32m ╚═════╝ ╚═════╝ ╚══════╝╚══════╝╚══════╝╚═╝ ╚═╝\x1b[0m`);
|
||||
console.log(`\x1b[2m ─────────────────────────────────────────────────\x1b[0m`);
|
||||
console.log(`\x1b[32m ONLINE\x1b[0m → \x1b[36mhttp://localhost:${server.port}\x1b[0m`);
|
||||
console.log(`\x1b[2m ─────────────────────────────────────────────────\x1b[0m\n`);
|
||||
console.log(`\x1b[32m[BUZZER]\x1b[0m → \x1b[36mhttp://localhost:${server.port}\x1b[0m`);
|
||||
Reference in New Issue
Block a user