在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:zadzbw/koa2-cors开源软件地址:https://github.com/zadzbw/koa2-cors开源编程语言:JavaScript 100.0%开源软件介绍:koa2-corsinstall
npm install --save koa2-cors Usagevar Koa = require('koa');
var cors = require('koa2-cors');
var app = new Koa();
app.use(cors()); OptionsoriginConfigures the Access-Control-Allow-Origin CORS header. expects a string. Can also be set to a function, which takes the exposeHeadersConfigures the Access-Control-Expose-Headers CORS header. Expects a comma-delimited array. maxAgeConfigures the Access-Control-Max-Age CORS header. Expects a Number. credentialsConfigures the Access-Control-Allow-Credentials CORS header. Expects a Boolean. allowMethodsConfigures the Access-Control-Allow-Methods CORS header. Expects a comma-delimited array , If not specified, default allowMethods is allowHeadersConfigures the Access-Control-Allow-Headers CORS header. Expects a comma-delimited array . If not specified, defaults to reflecting the headers specified in the request's Access-Control-Request-Headers header. var Koa = require('koa');
var cors = require('koa2-cors');
var app = new Koa();
app.use(cors({
origin: function(ctx) {
if (ctx.url === '/test') {
return false;
}
return '*';
},
exposeHeaders: ['WWW-Authenticate', 'Server-Authorization'],
maxAge: 5,
credentials: true,
allowMethods: ['GET', 'POST', 'DELETE'],
allowHeaders: ['Content-Type', 'Authorization', 'Accept'],
}));
... License |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论