safer port logic, log listening URL
This commit is contained in:
parent
c4a2bfd20a
commit
cf7944fcdf
1 changed files with 16 additions and 2 deletions
18
src/index.js
18
src/index.js
|
|
@ -32,6 +32,20 @@ server.on("upgrade", (req, socket, head) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
server.listen({
|
let port = parseInt(process.env.PORT || "");
|
||||||
port: process.env.PORT || 8080,
|
|
||||||
|
if (isNaN(port)) port = 8080;
|
||||||
|
|
||||||
|
server.on("listening", () => {
|
||||||
|
const address = server.address();
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`Listening on http://${
|
||||||
|
address.family === "IPv6" ? `[${address.address}]` : address.address
|
||||||
|
}:${address.port}`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
server.listen({
|
||||||
|
port,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue