diff options
author | Sebastian <sebasjm@gmail.com> | 2023-03-15 07:23:20 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-03-15 07:23:20 -0300 |
commit | 0700bbe9d14c7e0c6c2e998285a40d56e8b1d5cc (patch) | |
tree | 5c560496adbe6bb944b6e66c9446631ce45d23c8 | |
parent | 41339c1db25306d8135084d24b1452a3ddd75dbb (diff) |
always use both servers
-rw-r--r-- | packages/web-util/src/serve.ts | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/packages/web-util/src/serve.ts b/packages/web-util/src/serve.ts index 597303ba2..f37ef90ce 100644 --- a/packages/web-util/src/serve.ts +++ b/packages/web-util/src/serve.ts @@ -31,7 +31,6 @@ export async function serve(opts: { port: number; source?: string; development?: boolean; - insecure?: boolean; examplesLocationJs?: string; examplesLocationCss?: string; onUpdate?: () => Promise<void>; @@ -39,10 +38,10 @@ export async function serve(opts: { const app = express(); app.use(PATHS.APP, express.static(opts.folder)); - const server = opts.insecure - ? http.createServer(app) - : https.createServer(httpServerOptions, app); - logger.info(`serving ${opts.folder} on ${opts.port}`); + const servers = [ + http.createServer(app), + https.createServer(httpServerOptions, app), + ]; logger.info(` ${PATHS.APP}: application`); logger.info(` ${PATHS.EXAMPLE}: examples`); logger.info(` ${PATHS.WS}: websocket`); @@ -55,15 +54,17 @@ export async function serve(opts: { ws.send("welcome"); }); - server.on("upgrade", function upgrade(request, socket, head) { - const { pathname } = parse(request.url || ""); - if (pathname === PATHS.WS) { - wss.handleUpgrade(request, socket, head, function done(ws) { - wss.emit("connection", ws, request); - }); - } else { - socket.destroy(); - } + servers.forEach(function addWSHandler(server) { + server.on("upgrade", function upgrade(request, socket, head) { + const { pathname } = parse(request.url || ""); + if (pathname === PATHS.WS) { + wss.handleUpgrade(request, socket, head, function done(ws) { + wss.emit("connection", ws, request); + }); + } else { + socket.destroy(); + } + }); }); const sendToAllClients = function (data: object): void { @@ -121,6 +122,9 @@ export async function serve(opts: { res.send("ok"); }); - server.listen(opts.port); + servers.forEach(function startServer(server, index) { + logger.info(`serving ${opts.folder} on ${opts.port + index}`); + server.listen(opts.port + index); + }); } } |