2021-10-11 00:21:57 +00:00
|
|
|
import { stub } from 'eltro'
|
2022-08-13 21:52:45 +00:00
|
|
|
import { ServiceCore } from 'service-core'
|
2021-07-03 13:56:53 +00:00
|
|
|
import Client from './helper.client.mjs'
|
|
|
|
import defaults from '../api/defaults.mjs'
|
2022-08-13 21:52:45 +00:00
|
|
|
import * as index from '../index.mjs'
|
2021-10-11 00:21:57 +00:00
|
|
|
|
2022-08-13 21:52:45 +00:00
|
|
|
export const port = 5030
|
|
|
|
|
|
|
|
export const log = {
|
2021-10-11 00:21:57 +00:00
|
|
|
log: stub(),
|
|
|
|
warn: stub(),
|
|
|
|
info: stub(),
|
|
|
|
error: stub(),
|
2021-10-11 03:39:01 +00:00
|
|
|
child: stub(),
|
2022-08-13 21:52:45 +00:00
|
|
|
event: {
|
|
|
|
warn: stub(),
|
|
|
|
info: stub(),
|
|
|
|
error: stub(),
|
|
|
|
}
|
2021-10-11 00:21:57 +00:00
|
|
|
}
|
2022-08-13 21:52:45 +00:00
|
|
|
log.child.returns(log)
|
|
|
|
|
|
|
|
let serverRunning = false
|
|
|
|
|
|
|
|
export function startServer() {
|
|
|
|
if (serverRunning) return Promise.resolve()
|
|
|
|
serverRunning = true
|
2021-10-11 00:21:57 +00:00
|
|
|
|
2022-08-13 21:52:45 +00:00
|
|
|
var core = new ServiceCore('storage-upload', import.meta.url, port, '')
|
|
|
|
core.setConfig({
|
|
|
|
"port": port,
|
|
|
|
"sites": {
|
|
|
|
"development": {
|
|
|
|
"keys": {
|
|
|
|
"default@HS256": "asdf1234"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"existing": {
|
|
|
|
"public": true,
|
|
|
|
"keys": {
|
|
|
|
"default@HS256": "asdf1234"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
core.log = log
|
|
|
|
|
|
|
|
return core.init(index).then(function() {
|
|
|
|
return core.run()
|
|
|
|
})
|
|
|
|
}
|
2021-10-11 03:39:01 +00:00
|
|
|
|
2017-12-09 21:51:18 +00:00
|
|
|
|
2021-07-03 13:56:53 +00:00
|
|
|
export function createClient() {
|
2022-08-13 21:52:45 +00:00
|
|
|
return new Client(port)
|
2021-07-03 13:56:53 +00:00
|
|
|
}
|
2017-12-10 09:45:38 +00:00
|
|
|
|
2021-10-11 00:21:57 +00:00
|
|
|
export function resetLog() {
|
2022-08-13 21:52:45 +00:00
|
|
|
log.log.reset()
|
|
|
|
log.info.reset()
|
|
|
|
log.warn.reset()
|
|
|
|
log.error.reset()
|
2021-10-11 00:21:57 +00:00
|
|
|
}
|
|
|
|
|
2017-12-10 09:45:38 +00:00
|
|
|
export function createContext(opts) {
|
|
|
|
return defaults(opts, {
|
2021-10-11 00:21:57 +00:00
|
|
|
query: new Map(),
|
2022-01-05 14:47:51 +00:00
|
|
|
params: { },
|
2017-12-10 09:45:38 +00:00
|
|
|
req: { },
|
|
|
|
res: { },
|
2022-01-05 14:47:51 +00:00
|
|
|
state: {},
|
2021-10-11 00:21:57 +00:00
|
|
|
log: {
|
|
|
|
log: stub(),
|
|
|
|
warn: stub(),
|
|
|
|
info: stub(),
|
|
|
|
error: stub(),
|
|
|
|
},
|
2017-12-10 09:45:38 +00:00
|
|
|
})
|
|
|
|
}
|