|
|
@@ -10,7 +10,18 @@ import {
|
|
|
const app = new Koa()
|
|
|
|
|
|
app.context.redis = koaRedis(redisConfig);
|
|
|
-
|
|
|
+app.use(async (ctx, next) => {
|
|
|
+ ctx.set('Access-Control-Allow-Origin', '*')
|
|
|
+ ctx.set('Access-Control-Allow-Headers', 'content-type')
|
|
|
+ ctx.set('Access-Control-Allow-Methods', 'OPTIONS,GET,PUT,POST,DELETE')
|
|
|
+ await next()
|
|
|
+ // 允许所有跨域
|
|
|
+ if (ctx.request.method === 'OPTIONS') {
|
|
|
+ console.log('跨域请求')
|
|
|
+ ctx.response.status = 200
|
|
|
+ ctx.response.message = 'OK'
|
|
|
+ }
|
|
|
+ })
|
|
|
app.use(bodyParser());//中间件
|
|
|
app.use(router.routes()); //路由
|
|
|
//监听端口
|