sc-helloworld/api/server.mjs
Jonatan Nilsson 4dab6ea05d
All checks were successful
continuous-integration/appveyor/branch AppVeyor build succeeded
server: Read local package.json as opposed to the one in the runner folder
2022-03-12 22:33:28 +00:00

22 lines
No EOL
709 B
JavaScript

import { readFileSync } from 'fs'
import { Util } from 'service-core'
export function run(http, orgPort, ctx) {
let localUtil = new Util(import.meta.url)
let packagePath = localUtil.getPathFromRoot('../package.json')
let packageInfo = JSON.parse(readFileSync(packagePath))
const server = http.createServer(function (req, res) {
res.writeHead(200);
res.write(JSON.stringify(packageInfo, null, ' '))
res.end()
})
let port = orgPort || 4000
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}`)
})
}