2018-06-25 10:07:10 +00:00
|
|
|
const config = require('./config')
|
|
|
|
const Koa = require('koa')
|
|
|
|
const koaLogger = require('koa-logger')
|
2018-08-12 15:31:09 +00:00
|
|
|
const koaSession = require('koa-session2')
|
2018-08-17 14:52:41 +00:00
|
|
|
const cors = require('kcors')
|
2018-06-25 10:07:10 +00:00
|
|
|
const router = require('./route')
|
|
|
|
const app = new Koa()
|
|
|
|
|
|
|
|
app.use(koaLogger())
|
2018-08-17 14:52:41 +00:00
|
|
|
app.use(cors({
|
2018-08-17 15:49:50 +00:00
|
|
|
credentials: true,
|
2018-08-17 14:52:41 +00:00
|
|
|
origin: (c) => {
|
|
|
|
return c.get('Origin')
|
|
|
|
}
|
|
|
|
}))
|
2018-08-12 15:31:09 +00:00
|
|
|
app.use(koaSession())
|
2018-06-25 10:07:10 +00:00
|
|
|
app.use(router.allowedMethods())
|
|
|
|
app.use(router.routes())
|
|
|
|
|
|
|
|
const server = app.listen(config.port, () => {
|
|
|
|
console.log(`server start on port ${server.address().port}`)
|
|
|
|
})
|
|
|
|
|
|
|
|
module.exports = server
|