Skip to content

Commit

Permalink
Create WebSocketServer.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Mqxx authored Mar 29, 2023
1 parent df780a2 commit 65916be
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions WebSocketServer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export function WebSocketServer(options : Deno.ServeOptions | Deno.ServeTlsOptions, handler : (webSocket : WebSocket) => void) {
Deno.serve(options, (request) => {
if (request.headers.get("upgrade") != "websocket") {
return new Response(null, { status: 501 });
}
const {socket, response} = Deno.upgradeWebSocket(request)

handler(socket)

return response
})
}

0 comments on commit 65916be

Please # to comment.