2020-09-04 11:03:59 +00:00
|
|
|
import path from 'path'
|
|
|
|
import { readFileSync } from 'fs'
|
|
|
|
import { fileURLToPath } from 'url'
|
|
|
|
|
2020-09-09 13:54:26 +00:00
|
|
|
export function run(config, db, log, core, http) {
|
2020-09-04 11:03:59 +00:00
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
|
|
const staticPackage = path.join(__dirname,'../package.json')
|
2020-09-09 13:54:26 +00:00
|
|
|
let packageInfo = JSON.parse(readFileSync(staticPackage))
|
2020-09-04 11:03:59 +00:00
|
|
|
|
|
|
|
const server = http.createServer(function (req, res) {
|
|
|
|
res.writeHead(200);
|
2020-09-09 13:54:26 +00:00
|
|
|
res.write(JSON.stringify(packageInfo, null, ' '))
|
2020-09-04 11:03:59 +00:00
|
|
|
res.end()
|
|
|
|
})
|
|
|
|
|
2020-09-09 13:54:26 +00:00
|
|
|
let port = config.port || 4000
|
2020-09-04 11:03:59 +00:00
|
|
|
|
|
|
|
server.listen(port, '0.0.0.0', function(err) {
|
|
|
|
if (err) {
|
|
|
|
log.fatal(err)
|
|
|
|
log.event.error('Error starting server: ' + err.message)
|
|
|
|
return process.exit(2)
|
|
|
|
}
|
|
|
|
log.event.info(`Server is listening on ${port} serving package ${staticPackage}`)
|
|
|
|
log.info(`Server is listening on ${port} serving package ${staticPackage}`)
|
|
|
|
})
|
|
|
|
}
|