prepare websockets

This commit is contained in:
marlonerler
2024-07-04 16:18:40 +02:00
parent c97e3b5450
commit 40b393b6b3
3 changed files with 24 additions and 7 deletions
+14 -1
View File
@@ -8,8 +8,11 @@ const errorPage = "404.html";
// SERVER
const server = Bun.serve({
fetch(request, server) {
const requestPath = new URL(request.url).pathname;
// allow websockets
server.upgrade(request);
// respond
const requestPath = new URL(request.url).pathname;
try {
switch (requestPath) {
case "/":
@@ -21,6 +24,16 @@ const server = Bun.serve({
return createFileResponse(errorPage);
}
},
websocket: {
open(ws) {
},
message(ws, message) {
},
close(ws, code, reason) {},
},
});
function createFileResponse(requestPath: string): Response {