diff --git a/backend/server.ts b/backend/server.ts index 31e29ee..c210229 100644 --- a/backend/server.ts +++ b/backend/server.ts @@ -15,6 +15,7 @@ import { monitorAlplaPurchase } from "./purchase/purchase.controller.js"; import { setupSocketIORoutes } from "./socket.io/serverSetup.js"; import { baseSettingValidationCheck } from "./system/settingsBase.controller.js"; import { createCronJob } from "./utils/croner.utils.js"; +import { sendEmail } from "./utils/sendEmail.utils.js"; const port = Number(process.env.PORT) || 3000; export let systemSettings: Setting[] = []; @@ -62,6 +63,23 @@ const start = async () => { startNotifications(); }, 5 * 1000); + process.on("uncaughtException", async (err) => { + console.error("Uncaught Exception:", err); + //await closePool(); + const emailData = { + email: "blake.matthes@alpla.com", // should be moved to the db so it can be reused. + subject: `${os.hostname()} has just encountered a crash.`, + template: "serverCrash", + context: { + error: err, + plant: `${os.hostname()}`, + }, + }; + + await sendEmail(emailData); + //process.exit(1); + }); + server.listen(port, async () => { log.info( `Listening on http://${os.hostname()}:${port}${baseUrl}, logging in ${process.env.LOG_LEVEL}, current ENV ${process.env.NODE_ENV ? process.env.NODE_ENV : "development"}`, diff --git a/backend/utils/mailViews/serverCrash.hbs b/backend/utils/mailViews/serverCrash.hbs new file mode 100644 index 0000000..4b47f51 --- /dev/null +++ b/backend/utils/mailViews/serverCrash.hbs @@ -0,0 +1,35 @@ + +
+ + + {{!--+ Please see below the stack error from the crash. +
+{{error.message}}
+{{{error.stack}}}
+