-
Notifications
You must be signed in to change notification settings - Fork 15
/
app.mjs
49 lines (41 loc) · 1013 Bytes
/
app.mjs
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
49
import express from 'express'
import bodyParser from 'body-parser'
import { AppLoger, logger } from './logger.mjs'
import dayjs from 'dayjs'
import { route } from './router/api.mjs'
import { queryRecord } from './db.mjs'
import { startCron } from './cron.mjs'
import { AppEnv } from './env.mjs'
const app = express()
app.use(AppLoger())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(express.static('public'))
app.set('view engine', 'ejs')
if (AppEnv.enableCron === 'yes') {
logger.info('enable crontab')
startCron()
} else {
logger.info('disable crontab')
}
app.get('/', async function (req, res) {
let n = dayjs()
let day = n.format('YYYY-MM-DD')
let start = n.subtract(10, 'm').format('HH:mm:ss')
let stop = n.format('HH:mm:ss')
let result = await queryRecord({
day,
start,
stop,
caller: '',
callee: '',
msg_min: 1
})
res.render('home/index', {
day,
start,
stop,
table: result.rows
})
})
app.use('/api', route)
app.listen(3000)