Basic hello world SC service
This commit is contained in:
parent
e19dcc1028
commit
1bacd2f132
6 changed files with 1083 additions and 0 deletions
28
api/server.mjs
Normal file
28
api/server.mjs
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
import http from 'http'
|
||||||
|
import path from 'path'
|
||||||
|
import { readFileSync } from 'fs'
|
||||||
|
import { fileURLToPath } from 'url'
|
||||||
|
|
||||||
|
export function run(config, db, log, core) {
|
||||||
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
||||||
|
const staticPackage = path.join(__dirname,'../package.json')
|
||||||
|
config = JSON.parse(readFileSync(staticPackage))
|
||||||
|
|
||||||
|
const server = http.createServer(function (req, res) {
|
||||||
|
res.writeHead(200);
|
||||||
|
res.write(JSON.stringify(config, null, ' '))
|
||||||
|
res.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
let port = config.managePort || 4000
|
||||||
|
|
||||||
|
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}`)
|
||||||
|
})
|
||||||
|
}
|
5
index.mjs
Normal file
5
index.mjs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
export function start(config, db, log, core) {
|
||||||
|
return import('./api/server.mjs').then(function(module) {
|
||||||
|
return module.run(config, db, log, core)
|
||||||
|
})
|
||||||
|
}
|
1003
package-lock.json
generated
Normal file
1003
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
23
package.json
Normal file
23
package.json
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
{
|
||||||
|
"name": "sc-helloworld",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Hello World app for service core",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "nodemon --watch api --watch runner.mjs --watch index.mjs runner.mjs",
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/TheThing/sc-helloworld.git"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "WTFPL",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/TheThing/sc-helloworld/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/TheThing/sc-helloworld#readme",
|
||||||
|
"devDependencies": {
|
||||||
|
"nodemon": "^2.0.4"
|
||||||
|
}
|
||||||
|
}
|
8
publish.bat
Normal file
8
publish.bat
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
@ECHO off
|
||||||
|
SETLOCAL EnableDelayedExpansion
|
||||||
|
|
||||||
|
ECHO.
|
||||||
|
set /p version="Print version you wanna publish: "
|
||||||
|
ECHO.
|
||||||
|
ECHO !version!
|
||||||
|
ECHO.
|
16
runner.mjs
Normal file
16
runner.mjs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import('./index.mjs').then(function(module) {
|
||||||
|
return module.start({}, {}, {
|
||||||
|
debug: console.log.bind(console),
|
||||||
|
info: console.log.bind(console),
|
||||||
|
warn: console.log.bind(console),
|
||||||
|
error: console.error.bind(console),
|
||||||
|
fatal: console.error.bind(console),
|
||||||
|
event: {
|
||||||
|
debug: function() {},
|
||||||
|
info: function() {},
|
||||||
|
warn: function() {},
|
||||||
|
error: function() {},
|
||||||
|
fatal: function() {},
|
||||||
|
}
|
||||||
|
}, {})
|
||||||
|
})
|
Loading…
Reference in a new issue