25 lines
562 B
JavaScript
25 lines
562 B
JavaScript
const config = require('./config')
|
|
const Koa = require('koa')
|
|
const koaLogger = require('koa-logger')
|
|
const koaSession = require('koa-session2')
|
|
const cors = require('kcors')
|
|
const router = require('./route')
|
|
const app = new Koa()
|
|
|
|
app.use(koaLogger())
|
|
app.use(cors({
|
|
credentials: true,
|
|
origin: (c) => {
|
|
return c.get('Origin')
|
|
}
|
|
}))
|
|
app.use(koaSession())
|
|
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
|