From 76bcdbcf6e74b7ae2f6da24a5c01471c0b73948b Mon Sep 17 00:00:00 2001 From: pplokijuhyg <1162963624@qq.com> Date: Tue, 14 Jan 2020 09:44:01 +0800 Subject: [PATCH] =?UTF-8?q?options=E8=B7=A8=E5=9F=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 10 ++++++++++ 1 file changed, 10 insertions(+) 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", "*");