Skip to content

Commit

Permalink
feat: add support for custom HTTP server in WebSocket server options
Browse files Browse the repository at this point in the history
  • Loading branch information
richenlin committed Nov 27, 2024
1 parent 6298470 commit fbe0a9a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/server/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export function NewServe(app: KoattyApplication, opt?: ListeningOptions): Koatty
key: "",
cert: "",
protoFile: "",
server: null, // used by websocket
},
...opt
};
Expand Down
20 changes: 13 additions & 7 deletions src/server/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,21 @@ export class WsServer implements KoattyServer {
this.options.wsOptions = { ...options.ext, ...{ noServer: true } }

this.server = new WebSocketServer(this.options.wsOptions);
if (this.options.protocol == "wss") {
const opt: httpsServerOptions = {
key: this.options.ext.key,
cert: this.options.ext.cert,
}
this.httpServer = httpsCreateServer(opt);
// set http server
if (options.ext.server) {
this.httpServer = options.ext.server;
} else {
this.httpServer = createServer();
if (this.options.protocol == "wss") {
const opt: httpsServerOptions = {
key: this.options.ext.key,
cert: this.options.ext.cert,
}
this.httpServer = httpsCreateServer(opt);
} else {
this.httpServer = createServer();
}
}

CreateTerminus(this);
}

Expand Down

0 comments on commit fbe0a9a

Please sign in to comment.