-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathindex.js
67 lines (57 loc) · 1.6 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
55
56
57
58
59
60
61
62
63
64
65
66
67
const bootMessage = require('@dadi/boot')
const colors = require('colors/safe')
const config = require('./config')
const packageJSON = require('./package.json')
const path = require('path')
const Server = require('./server')
class App {
printStartupMessage() {
const env = config.get('env')
const port =
config.get('server.protocol') === 'https'
? 443
: config.get('server.port')
// Where can the user access Publish?
const server = config.get('publicUrl.host')
? `${config.get('publicUrl.protocol')}://${config.get(
'publicUrl.host'
)}:${port}`
: `http://${config.get('server.host')}:${port}`
// Print out API.
const api = config.get('api')
const apiUrl = api.host && `${api.host}:${api.port}`
const footer = {
API: apiUrl || colors.red('Not connected')
}
if (env !== 'test') {
bootMessage.started({
body: {
Version: packageJSON.version,
'Node.js': Number(process.version.match(/^v(\d+\.\d+)/)[1]),
Environment: env
},
header: {
app: config.get('app.name')
},
footer,
server
})
}
}
run({configPath = path.join(process.cwd(), 'config')} = {}) {
// Initialise config.
config.initialise(configPath)
// Initialise startup message package.
if (config.get('env') !== 'test') {
bootMessage.start(packageJSON)
}
this.server = new Server()
return this.server.start().then(() => {
this.printStartupMessage()
})
}
stop() {
return this.server.stop()
}
}
module.exports = new App()