27 lines
568 B
JavaScript
27 lines
568 B
JavaScript
const Router = require('koa-router')
|
|
const koaBody = require('koa-body')
|
|
const {
|
|
chkObject
|
|
} = require('@libs/route-utils')
|
|
const DB = require('@libs/database')
|
|
const r = new Router()
|
|
|
|
r.use(async (c, n) => {
|
|
c.obj = {}
|
|
c.db = await DB.connect()
|
|
c.chkBody = chkObject.bind({body: c.request.body})
|
|
try {
|
|
await n()
|
|
} catch (err) {
|
|
console.log(err)
|
|
}
|
|
c.db.release()
|
|
})
|
|
|
|
r.post('/login', koaBody(), async (c, n) => {
|
|
if (!c.chkBody('account', 'string') || !c.chkBody('password', 'string')) throw new Error('DataFormat')
|
|
|
|
})
|
|
|
|
module.exports = r
|