sc-helloworld/api/server.mjs

22 lines
687 B
JavaScript
Raw Normal View History

2020-09-04 11:03:59 +00:00
import path from 'path'
import { readFileSync } from 'fs'
import { fileURLToPath } from 'url'
export function run(http, orgPort, ctx) {
let packagePath = ctx.util.getPathFromRoot('./package.json')
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
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
})
}