23 lines
575 B
JavaScript
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())
|