always use both servers
This commit is contained in:
parent
41339c1db2
commit
0700bbe9d1
@ -31,7 +31,6 @@ export async function serve(opts: {
|
|||||||
port: number;
|
port: number;
|
||||||
source?: string;
|
source?: string;
|
||||||
development?: boolean;
|
development?: boolean;
|
||||||
insecure?: boolean;
|
|
||||||
examplesLocationJs?: string;
|
examplesLocationJs?: string;
|
||||||
examplesLocationCss?: string;
|
examplesLocationCss?: string;
|
||||||
onUpdate?: () => Promise<void>;
|
onUpdate?: () => Promise<void>;
|
||||||
@ -39,10 +38,10 @@ export async function serve(opts: {
|
|||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
app.use(PATHS.APP, express.static(opts.folder));
|
app.use(PATHS.APP, express.static(opts.folder));
|
||||||
const server = opts.insecure
|
const servers = [
|
||||||
? http.createServer(app)
|
http.createServer(app),
|
||||||
: https.createServer(httpServerOptions, app);
|
https.createServer(httpServerOptions, app),
|
||||||
logger.info(`serving ${opts.folder} on ${opts.port}`);
|
];
|
||||||
logger.info(` ${PATHS.APP}: application`);
|
logger.info(` ${PATHS.APP}: application`);
|
||||||
logger.info(` ${PATHS.EXAMPLE}: examples`);
|
logger.info(` ${PATHS.EXAMPLE}: examples`);
|
||||||
logger.info(` ${PATHS.WS}: websocket`);
|
logger.info(` ${PATHS.WS}: websocket`);
|
||||||
@ -55,15 +54,17 @@ export async function serve(opts: {
|
|||||||
ws.send("welcome");
|
ws.send("welcome");
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("upgrade", function upgrade(request, socket, head) {
|
servers.forEach(function addWSHandler(server) {
|
||||||
const { pathname } = parse(request.url || "");
|
server.on("upgrade", function upgrade(request, socket, head) {
|
||||||
if (pathname === PATHS.WS) {
|
const { pathname } = parse(request.url || "");
|
||||||
wss.handleUpgrade(request, socket, head, function done(ws) {
|
if (pathname === PATHS.WS) {
|
||||||
wss.emit("connection", ws, request);
|
wss.handleUpgrade(request, socket, head, function done(ws) {
|
||||||
});
|
wss.emit("connection", ws, request);
|
||||||
} else {
|
});
|
||||||
socket.destroy();
|
} else {
|
||||||
}
|
socket.destroy();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const sendToAllClients = function (data: object): void {
|
const sendToAllClients = function (data: object): void {
|
||||||
@ -121,6 +122,9 @@ export async function serve(opts: {
|
|||||||
res.send("ok");
|
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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user