未验证 提交 28c93612 编写于 作者: A Asher

Move address output to the listen callback

Since listening is asynchronous, this guarantees the address will be
filled out.
上级 a9d17882
......@@ -281,10 +281,32 @@ const bold = (text: string | number): string | number => {
if (options.socket) {
logger.info("Starting webserver via socket...", field("socket", options.socket));
app.server.listen(options.socket);
app.server.listen(options.socket, () => {
logger.info(" ");
logger.info("Started on socket address:");
logger.info(options.socket!);
logger.info(" ");
});
} else {
logger.info("Starting webserver...", field("host", options.host), field("port", options.port));
app.server.listen(options.port, options.host);
app.server.listen(options.port, options.host, async () => {
const protocol = options.allowHttp ? "http" : "https";
const address = app.server.address();
const port = typeof address === "string" ? options.port : address.port;
const url = `${protocol}://localhost:${port}/`;
logger.info(" ");
logger.info("Started (click the link below to open):");
logger.info(url);
logger.info(" ");
if (options.open) {
try {
await opn(url);
} catch (e) {
logger.warn("Url couldn't be opened automatically.", field("url", url), field("error", e.message));
}
}
});
}
let clientId = 1;
app.wss.on("connection", (ws, req) => {
......@@ -327,26 +349,6 @@ const bold = (text: string | number): string | number => {
logger.info(" ");
logger.info("Telemetry is disabled.");
}
logger.info(" ");
if (options.socket) {
logger.info("Started on socket address:");
logger.info(options.socket);
} else {
const protocol = options.allowHttp ? "http" : "https";
const url = `${protocol}://localhost:${app.server.address().port}/`;
logger.info("Started (click the link below to open):");
logger.info(url);
}
logger.info(" ");
if (options.open) {
try {
await opn(url);
} catch (e) {
logger.warn("Url couldn't be opened automatically.", field("url", url), field("exception", e));
}
}
})().catch((ex) => {
logger.error(ex);
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册