koa-template/server.js

30 lines
717 B
JavaScript
Raw Normal View History

2019-12-18 02:59:34 +00:00
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')
2019-12-18 06:16:19 +00:00
const koaBody = require('koa-body')
2019-12-18 02:59:34 +00:00
const rootRouter = require('@route/index.js')
app.use(koaLogger())
app.use(koaCors({
credentials: true,
// allow all origin
origin: ctx => ctx.get('origin')
}))
2019-12-18 06:16:19 +00:00
app.use(koaBody({
multipart: true,
formidable: {
maxFileSize: 100 * 1024 * 1024 // 100 mb
}
}))
2019-12-18 02:59:34 +00:00
app.use(rootRouter.allowedMethods())
app.use(rootRouter.routes())