-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
42 lines (41 loc) · 1.58 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/// <reference path="src/types/global.d.ts" />
import 'reflect-metadata';
import "dotenv/config"
import express from 'express';
import morgan from "morgan"
import cors from 'cors';
import path from 'path';
import { createServer } from 'http';
import { InversifyExpressServer } from 'inversify-express-utils';
import { initControllers } from './src/server/initControllers';
import { container , initContainers } from './src/server/globalContainer';
import { initWebSocket } from './src/core/infrastructure/adapter/websocket/initWebSocket';
import { initDatabase } from './src/core/infrastructure/database/initDatabase';
import { loadEntities } from './src/server/loadEntities';
import "colors"
async function bootstrap() {
console.time("Server up")
// const entities = await loadEntities()
await initDatabase()
await initContainers()
await initControllers()
const server = new InversifyExpressServer(container, null, { rootPath: `/api` });
server.setConfig((app) => {
app.use(express.json());
app.use(morgan("dev"))
app.use(cors({
origin: JSON.parse(process.env.TEST_CORS),
methods: ["GET",'POST'],
allowedHeaders: ['Content-Type', 'Authorization'],
}));
app.use(express.static(path.join(__dirname, 'public')));
});
const app = server.build();
const httpServer = createServer(app);
initWebSocket(httpServer)
const PORT = process.env.PORT || 3000;
httpServer.listen(PORT);
console.table(`>> Server up at port http://127.0.0.1:${PORT} <<`);
console.timeEnd("Server up")
}
bootstrap()