zappyzep/backend/src/api/index.ts

25 lines
648 B
TypeScript
Raw Normal View History

import { connect } from "../data/db";
import { setIsAPI } from "../globals";
import "./loadEnv";
2020-09-16 22:32:43 +03:00
if (!process.env.KEY) {
// tslint:disable-next-line:no-console
console.error("Project root .env with KEY is required!");
process.exit(1);
}
2019-08-04 15:45:35 +03:00
function errorHandler(err) {
2019-08-22 01:22:26 +03:00
console.error(err.stack || err); // tslint:disable-line:no-console
2019-08-04 15:45:35 +03:00
process.exit(1);
}
process.on("unhandledRejection", errorHandler);
setIsAPI(true);
// Connect to the database before loading the rest of the code (that depend on the database connection)
2019-08-22 01:22:26 +03:00
console.log("Connecting to database..."); // tslint:disable-line
2019-05-26 00:13:42 +03:00
connect().then(() => {
import("./start");
2019-05-26 00:13:42 +03:00
});