1
+ import * as dbTools from './database/dbTools'
2
+ import * as http from 'http' ;
3
+ import * as https from 'https' ;
4
+ import * as eventHandlers from './api/server/eventHandlers' ;
5
+ import server from './api/server/server' ;
6
+ import * as loggingUtil from './app/loggingUtil'
7
+ import * as dotEnv from 'dotenv'
8
+ import { readFileSync } from 'fs' ;
9
+ import * as app from "./app" ;
10
+
11
+ dotEnv . config ( ) ;
12
+
13
+ dbTools . dbExists ( ) . then ( ( ) => {
14
+
15
+ /**
16
+ * API
17
+ */
18
+ if ( process . env . USE_HTTPS === 'true' ) {
19
+ const options = {
20
+ key : readFileSync ( process . env . KEY_LOCATION ) ,
21
+ cert : readFileSync ( process . env . CERT_LOCATION ) ,
22
+ } ;
23
+ const Server : https . Server = https . createServer ( options , server ) ;
24
+ Server . listen ( process . env . PORT ) ;
25
+ loggingUtil . logInfo ( 'Server running at port ' + process . env . PORT ) ;
26
+ Server . on ( 'error' , ( error : Error ) => eventHandlers . onError ( error , process . env . PORT ) ) ;
27
+ Server . on ( 'listening' , eventHandlers . onListening . bind ( Server ) ) ;
28
+
29
+ } else {
30
+ const Server : http . Server = http . createServer ( server ) ;
31
+ Server . listen ( process . env . PORT ) ;
32
+ loggingUtil . logInfo ( 'Server running at port ' + process . env . PORT ) ;
33
+ Server . on ( 'error' , ( error : Error ) => eventHandlers . onError ( error , process . env . PORT ) ) ;
34
+ Server . on ( 'listening' , eventHandlers . onListening . bind ( Server ) ) ;
35
+
36
+ }
37
+
38
+ /**
39
+ * Jobs
40
+ */
41
+ app . app ( ) ;
42
+
43
+ } ) . catch ( ( ) => {
44
+ process . exit ( ) ;
45
+ } ) ;
0 commit comments