7
7
8
8
/** @typedef {{port: number, close: () => Promise<void>, storageMethod: StorageMethod} } ServerInstance */
9
9
10
+ const log = require ( 'debug' ) ( 'lhci:server:sql' ) ;
10
11
const path = require ( 'path' ) ;
11
12
const createHttpServer = require ( 'http' ) . createServer ;
12
13
const express = require ( 'express' ) ;
@@ -30,9 +31,11 @@ const DIST_FOLDER = path.join(__dirname, '../dist');
30
31
async function createApp ( options ) {
31
32
const { storage} = options ;
32
33
34
+ log ( '[createApp] initializing storage method' ) ;
33
35
const storageMethod = StorageMethod . from ( storage ) ;
34
36
await storageMethod . initialize ( storage ) ;
35
37
38
+ log ( '[createApp] creating express app' ) ;
36
39
const context = { storageMethod, options} ;
37
40
const app = express ( ) ;
38
41
if ( options . logLevel !== 'silent' ) app . use ( morgan ( 'short' ) ) ;
@@ -58,6 +61,7 @@ async function createApp(options) {
58
61
app . get ( '/app/*' , ( _ , res ) => res . sendFile ( path . join ( DIST_FOLDER , 'index.html' ) ) ) ;
59
62
app . use ( errorMiddleware ) ;
60
63
64
+ log ( '[createApp] launching cron jobs' ) ;
61
65
startPsiCollectCron ( storageMethod , options ) ;
62
66
startDeleteOldBuildsCron ( storageMethod , options ) ;
63
67
@@ -71,7 +75,7 @@ async function createApp(options) {
71
75
async function createServer ( options ) {
72
76
const { app, storageMethod} = await createApp ( options ) ;
73
77
74
- return new Promise ( resolve => {
78
+ return new Promise ( ( resolve , reject ) => {
75
79
const server = createHttpServer ( app ) ;
76
80
77
81
// Node default socket timeout is 2 minutes.
@@ -88,6 +92,8 @@ async function createServer(options) {
88
92
} ) ;
89
93
} ) ;
90
94
95
+ server . on ( 'error' , err => reject ( err ) ) ;
96
+
91
97
server . listen ( options . port , ( ) => {
92
98
const serverAddress = server . address ( ) ;
93
99
const listenPort =
0 commit comments