Skip to content

Commit

Permalink
fix: fix ws server (#623)
Browse files Browse the repository at this point in the history
  • Loading branch information
KhudaDad414 authored Dec 4, 2023
1 parent d2d4264 commit 994b957
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/adapters/ws/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,16 @@ class WebSocketsAdapter extends Adapter {
private async _connect(): Promise<this> {
this._validatePort()
this._createServers()
this.wsHttpServer.on('upgrade', this._onUpgrade)

this.wsHttpServer.on('upgrade', (request: IncomingMessage, socket: Duplex, head: Buffer) => {
try {
this._handleRequest(request, socket, head)
} catch (e) {
const errorMessage = `Error handling request: ${e.message}`
this.emit('error', new Error(errorMessage))
if (!socket.writableEnded) this._endRequest(500, 'Internal Server Error', socket)
}
})

if (!this.customHttpServer) {
this.wsHttpServer.listen(this._getPort())
Expand Down Expand Up @@ -170,15 +179,6 @@ class WebSocketsAdapter extends Adapter {
})
}

private async _onUpgrade(request: IncomingMessage, socket: Duplex, head: Buffer) {
try {
this._handleRequest(request, socket, head)
} catch (e) {
const errorMessage = `Error handling request: ${e.message}`
this.emit('error', new Error(errorMessage))
if (!socket.writableEnded) this._endRequest(500, 'Internal Server Error', socket)
}
}

private _extractPathname(req: IncomingMessage) {
const serverUrl = new URL(this.serverUrlExpanded)
Expand Down

0 comments on commit 994b957

Please sign in to comment.