-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathserver.ts
74 lines (62 loc) · 1.93 KB
/
server.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* @summary Boots up the server, initializes and loads every required module in order to assure server functions normally.
*/
import Db from './db/index.ts';
import Config from './lib/Config.ts';
import Router from './lib/Router.ts';
import Logger from './lib/Logger.ts';
import CronLoader from './lib/CronLoader.ts';
import ModelLoader from './lib/ModelLoader.ts';
import RouteLoader from './lib/RouteLoader.ts';
import HttpOriginReader from './http/HttpOriginReader.ts';
import { Application } from 'https://deno.land/x/oak/mod.ts';
import FeatureFlagReader from './lib/FeatureFlagReader.ts';
import FactoryLoader from './lib/FactoryLoader.ts';
/**
* @summary Reads all feature flags to determine behavior of the server
*/
await FeatureFlagReader.readAll();
/**
* @summary Instantiating instance of Application
*/
const app : Application = new Application();
/**
* @summary Loading allowed HTTP origins
*/
Logger.debug('Loading all allowed HTTP origins...');
await HttpOriginReader.fetchOrigins(app);
/**
* @summary Initializing router and its routes
*/
Logger.debug('Initializing router...');
app.use(Router.routes());
app.use(Router.allowedMethods());
await RouteLoader.loadRoutes();
/**
* @summary Instantiates Database
*/
Logger.debug('Instantiating the database...');
const db = new Db({ debug: true });
/**
* @summary Loads and links models that directly correlate to DB tables
*/
Logger.debug('Loading all DB models and linking them to the database...');
const models = await ModelLoader.loadDbModels();
db.link(models);
/**
* @summary Loads and instantiates CRON jobs
*/
Logger.debug('Loading all CRON jobs...');
await CronLoader.loadCronJobs();
/**
* @summary Load and run factories
*/
await FactoryLoader.loadAndRunFactories();
/**
* @summary Instantiating listener
*/
const port : any = Config.getApiPort();
Logger.info(`Server successfully started and listening to port: ${port}`);
await app.listen({
port: parseInt(port)
});