Add UNSAFE last-resort measure to prevent crashes

This is really unsafe, according to Node.js's docs (see link below).
Therefore, this handler is only added if the UNSAFE_CONTINUE environment
variable has a truthy value.

https://nodejs.org/api/process.html#warning-using-uncaughtexception-correctly
This commit is contained in:
CountBleck 2022-08-30 15:26:46 -07:00
parent 4ff19c9fa5
commit a9e3b27cb5

8
app.js
View file

@ -44,4 +44,12 @@ server.on('upgrade', (req, socket, head) => {
server.listen(PORT);
if (process.env.UNSAFE_CONTINUE)
process.on("uncaughtException", (err, origin) => {
console.error(`Critical error (${origin}):`)
console.error(err)
console.error("UNSAFELY CONTINUING EXECUTION")
console.error()
})
console.log(`Server running at http://localhost:${PORT}/.`);