* @private * @returns {Promise }
()
| 2522 | * @returns {Promise<void>} |
| 2523 | */ |
| 2524 | async createServer() { |
| 2525 | const { type, options } = |
| 2526 | /** @type {ServerConfiguration<A, S>} */ |
| 2527 | (this.options.server); |
| 2528 | |
| 2529 | if (typeof type === "function") { |
| 2530 | /** @type {S | undefined} */ |
| 2531 | this.server = await type( |
| 2532 | /** @type {ServerOptions} */ |
| 2533 | (options), |
| 2534 | /** @type {A} */ |
| 2535 | (this.app), |
| 2536 | ); |
| 2537 | } else { |
| 2538 | const mod = cjsRequire(/** @type {string} */ (type)); |
| 2539 | |
| 2540 | const serverType = mod.default || mod; |
| 2541 | |
| 2542 | /** @type {S | undefined} */ |
| 2543 | this.server = |
| 2544 | type === "http2" |
| 2545 | ? serverType.createSecureServer( |
| 2546 | { ...options, allowHTTP1: true }, |
| 2547 | this.app, |
| 2548 | ) |
| 2549 | : serverType.createServer(options, this.app); |
| 2550 | } |
| 2551 | |
| 2552 | this.isTlsServer = |
| 2553 | typeof ( |
| 2554 | /** @type {import("tls").Server} */ (this.server).setSecureContext |
| 2555 | ) !== "undefined"; |
| 2556 | |
| 2557 | /** @type {S} */ |
| 2558 | (this.server).on( |
| 2559 | "connection", |
| 2560 | /** |
| 2561 | * @param {Socket} socket connected socket |
| 2562 | */ |
| 2563 | (socket) => { |
| 2564 | // Add socket to list |
| 2565 | this.sockets.push(socket); |
| 2566 | |
| 2567 | socket.once("close", () => { |
| 2568 | // Remove socket from list |
| 2569 | this.sockets.splice(this.sockets.indexOf(socket), 1); |
| 2570 | }); |
| 2571 | }, |
| 2572 | ); |
| 2573 | |
| 2574 | /** @type {S} */ |
| 2575 | (this.server).on( |
| 2576 | "error", |
| 2577 | /** |
| 2578 | * @param {Error} error error |
| 2579 | */ |
| 2580 | (error) => { |
| 2581 | throw error; |
no outgoing calls