2020-12-04 20:38:34 +00:00
|
|
|
import consola from "consola";
|
|
|
|
import "reflect-metadata";
|
2020-11-25 18:28:12 +00:00
|
|
|
import { createExpressServer } from "routing-controllers";
|
2020-12-09 18:40:08 +00:00
|
|
|
import { config, e as errors } from './config';
|
2020-12-04 20:38:34 +00:00
|
|
|
import loaders from "./loaders/index";
|
2020-12-30 13:01:37 +00:00
|
|
|
import authchecker from "./middlewares/authchecker";
|
2020-11-27 20:24:55 +00:00
|
|
|
import { ErrorHandler } from './middlewares/ErrorHandler';
|
2021-01-15 21:16:28 +00:00
|
|
|
import UserChecker from './middlewares/UserChecker';
|
2020-11-24 18:28:57 +00:00
|
|
|
|
2020-12-12 11:39:53 +00:00
|
|
|
const CONTROLLERS_FILE_EXTENSION = process.env.NODE_ENV === 'production' ? 'js' : 'ts';
|
2020-11-25 18:28:12 +00:00
|
|
|
const app = createExpressServer({
|
2020-11-27 20:24:55 +00:00
|
|
|
authorizationChecker: authchecker,
|
2021-01-15 21:16:28 +00:00
|
|
|
currentUserChecker: UserChecker,
|
2020-12-05 16:59:43 +00:00
|
|
|
middlewares: [ErrorHandler],
|
2020-12-06 09:29:56 +00:00
|
|
|
development: config.development,
|
2020-11-27 18:32:54 +00:00
|
|
|
cors: true,
|
2020-11-27 18:32:29 +00:00
|
|
|
routePrefix: "/api",
|
2020-12-12 11:39:53 +00:00
|
|
|
controllers: [`${__dirname}/controllers/*.${CONTROLLERS_FILE_EXTENSION}`],
|
2020-11-25 18:28:12 +00:00
|
|
|
});
|
|
|
|
|
2020-11-25 17:31:06 +00:00
|
|
|
async function main() {
|
2020-11-27 17:46:04 +00:00
|
|
|
await loaders(app);
|
2021-03-06 12:51:24 +00:00
|
|
|
if (config.testing) {
|
|
|
|
consola.info("🛠[config]: Discovered testing env. Mailing errors will get ignored!")
|
|
|
|
}
|
2020-12-06 09:29:56 +00:00
|
|
|
app.listen(config.internal_port, () => {
|
2020-11-27 17:46:04 +00:00
|
|
|
consola.success(
|
2020-12-06 09:29:56 +00:00
|
|
|
`⚡️[server]: Server is running at http://localhost:${config.internal_port}`
|
2020-11-27 17:46:04 +00:00
|
|
|
);
|
|
|
|
});
|
2020-11-25 17:31:06 +00:00
|
|
|
}
|
2020-12-09 18:40:08 +00:00
|
|
|
if (errors === 0) {
|
|
|
|
main();
|
|
|
|
} else {
|
2020-12-10 16:44:17 +00:00
|
|
|
consola.error("error");
|
2020-12-09 18:40:08 +00:00
|
|
|
// something's wrong
|
|
|
|
}
|