diff options
Diffstat (limited to 'packages/web-util/src')
-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); + }); } } |