-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
28 lines (28 loc) · 1010 Bytes
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
setTimeout(() => {
const server = Bun.serve({
fetch(request) {
if ((new URL(request.url)).pathname.startsWith("/ws")) {
console.log('SERVER incoming request');
if (this.upgrade(request)) {
return;
}
}
console.log(`SERVER responded from: ${request.url}`);
return new Response("Welcome to Bun!\n");
},
websocket: {
open(ws) {
console.log(`SERVER open`);
ws.ping();
},
close(ws, code, reason) {
console.log(`SERVER close: code=${code} reason=${reason}`);
},
message(ws, message) {
console.log(`SERVER message: ${Bun.inspect(message)}`);
ws.send(`You said: ${message}`);
}
},
});
console.log(`SERVER started: ${server.port}`);
}, 5000) // This timeout is intended to simulate slow startup within proxy