diff --git a/app.js b/app.js index 00b6e79..b5ef590 100644 --- a/app.js +++ b/app.js @@ -10,6 +10,16 @@ reptile().then((res)=>{ reptilelist = res; }) const app = new Koa(); +app.use(async (ctx, next)=> { + ctx.set('Access-Control-Allow-Origin', '*'); + ctx.set('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild'); + ctx.set('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS'); + if (ctx.method == 'OPTIONS') { + ctx.body = 200; + } else { + await next(); + } + }); app.use(async (ctx, next) => { // 允许来自所有域名请求 ctx.set("Access-Control-Allow-Origin", "*");