diff --git a/packages/marketplace_server/src/index.js b/packages/marketplace_server/src/index.js index acb48ba9..a832be27 100644 --- a/packages/marketplace_server/src/index.js +++ b/packages/marketplace_server/src/index.js @@ -5,6 +5,7 @@ import { registerBaseAliases } from "linebridge/dist/server" registerBaseAliases(undefined, { "@services": path.resolve(__dirname, "services"), + "comty.js": path.resolve(__dirname, "../../comty.js/src"), }) // patches @@ -46,9 +47,35 @@ global.isProduction = process.env.NODE_ENV === "production" import API from "./api" async function main() { - const mainAPI = new API() + const instance = new API() - await mainAPI.initialize() + await instance.initialize() + + // kill on process exit + process.on("exit", () => { + instance.server.close() + process.exit(0) + }) + + // kill on ctrl+c + process.on("SIGINT", () => { + instance.server.close() + process.exit(0) + }) + + // kill on uncaught exceptions + process.on("uncaughtException", (error) => { + console.error(`🆘 [FATAL ERROR] >`, error) + instance.server.close() + process.exit(1) + }) + + // kill on unhandled rejections + process.on("unhandledRejection", (error) => { + console.error(`🆘 [FATAL ERROR] >`, error) + instance.server.close() + process.exit(1) + }) } main().catch((error) => {