mtfosbot/route/api/index.js

27 lines
568 B
JavaScript
Raw Normal View History

2018-08-11 15:28:00 +00:00
const Router = require('koa-router')
2018-08-14 06:17:48 +00:00
const koaBody = require('koa-body')
const {
chkObject
} = require('@libs/route-utils')
2018-08-14 09:30:27 +00:00
const DB = require('@libs/database')
2018-08-11 15:28:00 +00:00
const r = new Router()
2018-08-14 06:17:48 +00:00
r.use(async (c, n) => {
c.obj = {}
2018-08-14 09:30:27 +00:00
c.db = await DB.connect()
2018-08-14 06:17:48 +00:00
c.chkBody = chkObject.bind({body: c.request.body})
try {
await n()
} catch (err) {
console.log(err)
}
2018-08-14 09:30:27 +00:00
c.db.release()
2018-08-14 06:17:48 +00:00
})
r.post('/login', koaBody(), async (c, n) => {
2018-08-14 09:30:27 +00:00
if (!c.chkBody('account', 'string') || !c.chkBody('password', 'string')) throw new Error('DataFormat')
2018-08-14 06:17:48 +00:00
})
2018-08-11 15:28:00 +00:00
module.exports = r