-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
54 lines (43 loc) · 1.74 KB
/
index.js
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
/**
* Loads, starts and initializes the Tuna server. We separate the server from this the loader so we
* can have multiple loaders - the mocha tester has its own loader so we can mount the server from tests.
*
* Start your debugger on this file to launch a web server.
* Perf : raw startup time (node index) is 3200 ms
*/
// set shortcut global for easier module imports. Modules are loaded relative to "server" directory
global._$ = `${__dirname}/server/`
// load first to speed up app loads. Note that all module lode times in comments are with cache enabled
require('cache-require-paths')
// use stopwatch to measure start time
const
Stopwatch = require('statman-stopwatch'),
stopwatch = new Stopwatch()
stopwatch.start()
const
tunaServer = require(_$+'server'), // 2000ms
settings = require(_$+'helpers/settings'); // 12ms
(async ()=>{
try {
let
express = tunaServer.initialize(),
httpServer = null
if (settings.useSelfSignedSSL) {
const
certificateHelper = require(_$+'helpers/certificateHelper'),
https = require('https'),
keys = await certificateHelper()
httpServer = https.createServer({ key: keys.serviceKey, cert: keys.certificate }, express)
} else {
const http = require('http')
httpServer = http.createServer(express)
}
await tunaServer.start(httpServer) // 1200ms
httpServer.listen(settings.port, ()=>{
console.log(`Tuna started, listening on port ${httpServer.address().port}`)
console.log(`Tuna started in ${Math.floor(stopwatch.read())} ms`)
})
} catch(ex) {
console.error(ex)
}
})()