2020-09-04 11:03:59 +00:00
|
|
|
import { readFileSync } from 'fs'
|
2022-03-12 22:33:28 +00:00
|
|
|
import { Util } from 'service-core'
|
2020-09-04 11:03:59 +00:00
|
|
|
|
2022-03-10 15:19:22 +00:00
|
|
|
export function run(http, orgPort, ctx) {
|
2022-03-12 22:33:28 +00:00
|
|
|
let localUtil = new Util(import.meta.url)
|
|
|
|
let packagePath = localUtil.getPathFromRoot('../package.json')
|
2022-03-10 15:19:22 +00:00
|
|
|
let packageInfo = JSON.parse(readFileSync(packagePath))
|
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 14:32:23 +00:00
|
|
|
let port = orgPort || 4000
|
2020-09-04 11:03:59 +00:00
|
|
|
|
2022-03-10 15:19:22 +00:00
|
|
|
return server.listenAsync(port, '0.0.0.0')
|
|
|
|
.then(function() {
|
|
|
|
ctx.log.event.info(`Server is listening on ${port} serving package ${packagePath}`)
|
|
|
|
ctx.log.info(`Server is listening on ${port} serving package ${packagePath}`)
|
2020-09-04 11:03:59 +00:00
|
|
|
})
|
|
|
|
}
|