|
|
@@ -1,3 +1,30 @@
|
|
|
import Koa from 'koa'
|
|
|
-import Koa from 'koa'
|
|
|
+import bodyParser from 'koa-bodyparser'
|
|
|
+import koaJsonError from 'koa-json-error'
|
|
|
+import koaBody from 'koa-body'
|
|
|
+import cors from '@koa/cors'
|
|
|
+import config from 'config'
|
|
|
import router from '@/router'
|
|
|
+import { ConsoleRouters, Debug } from '@/tool/debug'
|
|
|
+
|
|
|
+const app = new Koa()
|
|
|
+const port = config.get<number>('app.port')
|
|
|
+const appName = config.get<string>('app.name')
|
|
|
+const consoleRouters: ConsoleRouters[] = []
|
|
|
+
|
|
|
+app.use(koaBody())
|
|
|
+app.use(bodyParser())
|
|
|
+app.use(cors())
|
|
|
+app.use(router.routes()).use(router.allowedMethods())
|
|
|
+
|
|
|
+if (process.env.NODE_ENV === 'development') {
|
|
|
+ app.use(koaJsonError())
|
|
|
+ router.stack.map(i => {
|
|
|
+ consoleRouters.push({ path: i.path, methods: i.methods.toString() })
|
|
|
+ })
|
|
|
+ Debug.consoleRouters(consoleRouters)
|
|
|
+}
|
|
|
+
|
|
|
+app.listen(port)
|
|
|
+
|
|
|
+console.log(`${appName} listening-port:${port}`)
|