koa-template/server.js
JayChen 5b85b57e99
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is failing
first version
2019-12-18 10:59:34 +08:00

23 lines
575 B
JavaScript

const Koa = require('koa')
const app = new Koa()
const config = require('@config/index.js')
const server = app.listen(config.server.port, () => {
console.log(`server start on port ${server.address().port}`)
})
module.exports = server
// load middleware module
const koaLogger = require('koa-logger')
const koaCors = require('@koa/cors')
const rootRouter = require('@route/index.js')
app.use(koaLogger())
app.use(koaCors({
credentials: true,
// allow all origin
origin: ctx => ctx.get('origin')
}))
app.use(rootRouter.allowedMethods())
app.use(rootRouter.routes())