options跨域
This commit is contained in:
parent
9bc59c1310
commit
76bcdbcf6e
10
app.js
10
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", "*");
|
||||
|
Loading…
Reference in New Issue
Block a user