-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (42 loc) · 1.36 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const logger = require('@brickyard/logger')
const _ = require('lodash')
const Koa = require('koa')
const body = require('koa-body')
const Koaqs = require('koa-qs')
const Server = require('./server')
const service = require('./service')
const config = require('./config.js')
const router = require('./koa-router')
const server = new Server()
const app = new Koa()
app.use(body({ multipart: true, strict: false }))
Koaqs(app)
const DEFAULT_OPTIONS = {
port: 6688,
}
const port = _.get(config, 'web.port') || _.get(DEFAULT_OPTIONS, 'port')
const host = _.get(config, 'web.host') || _.get(DEFAULT_OPTIONS, 'host')
server.on('message', ({ buffer }) => {
process.nextTick(() => {
try {
service.execute(buffer)
} catch (e) {
logger.console.error('[udp-echo-server error] %o', e)
}
})
})
server.on('error', (err) => { logger.console.error('[udp-echo-server error....] %s', err) })
async function start() {
await server.listen(port)
logger.console.info('Listen @ %s', port)
logger.console.info('PID: %s', process.pid)
logger.console.info('TTY MODE: %s', !!process.stdout.isTTY)
app.use(router.router.routes())
app.use(router.router.allowedMethods())
app.listen(port, host, () => {
console.log('Start Http Server @ %s:%s', host, port)
})
router.register_schedule('remove_overtime_record', '0 * * * * *', router.removeOvertimeRecord)
console.log('schedule start')
}
start()