-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
executable file
·63 lines (56 loc) · 2.03 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
#!/usr/bin/env node
'use strict'
const semver = require('semver')
const fileServer = require('./forge/fileServer')
const YAML = require('yaml')
const app = (async function () {
if (!semver.satisfies(process.version, '>=16.0.0')) {
console.error(`FlowFuse File Server requires at least NodeJS v16, ${process.version} found`)
process.exit(1)
}
try {
const options = {}
// The tests for `nr-persistent-context` run a local copy of the file-server
// and pass in the full config via this env var
if (process.env.FF_FS_TEST_CONFIG) {
try {
options.config = YAML.parse(process.env.FF_FS_TEST_CONFIG)
} catch (err) {
console.error('Failed to parse FF_FS_TEST_CONFIG:', err)
process.exitCode = 1
return
}
}
const server = await fileServer(options)
let stopping = false
async function exitWhenStopped () {
if (!stopping) {
stopping = true
server.log.info('Stopping FlowFuse File Server')
await server.close()
server.log.info('FlowFuse File Server stopped')
process.exit(0)
}
}
process.on('SIGINT', exitWhenStopped)
process.on('SIGTERM', exitWhenStopped)
process.on('SIGHUP', exitWhenStopped)
process.on('SIGUSR2', exitWhenStopped) // for nodemon restart
process.on('SIGBREAK', exitWhenStopped)
process.on('message', function (m) { // for PM2 under window with --shutdown-with-message
if (m === 'shutdown') { exitWhenStopped() }
})
// Start the server
server.listen({ port: server.config.port, host: server.config.host }, function (err, address) {
if (err) {
console.error(err)
process.exit(1)
}
})
return server
} catch (err) {
console.error(err)
process.exitCode = 1
}
})()
module.exports = app