跳到主要内容

cors - 跨域支持

跨域支持,请求接口时设置跨域头信息

依赖模块

快速使用

yarn add @zenweb/cors
import modCors from '@zenweb/cors';
// ...
.setup(modCors({ origin: '*' }))
// ...

配置项

配置项类型默认值功能
originstring \| (ctx: Contxt): string设置 Access-Control-Allow-Origin 来源域名
allowMethodsstring[] \| string'GET,HEAD,PUT,POST,DELETE,PATCH'设置 Access-Control-Allow-Methods 允许的方法
exposeHeadersstring[] \| stringAccess-Control-Expose-Headers
allowHeadersstring[] \| stringAccess-Control-Allow-Headers
maxAgenumber \| stringAccess-Control-Max-Age
credentialsboolean \| (ctx: Contxt): booleanAccess-Control-Allow-Credentials
keepHeadersOnErrorboolean
secureContextbooleanAdd Cross-Origin-Opener-Policy & Cross-Origin-Embedder-Policy to response headers
privateNetworkAccessbooleanHandle Access-Control-Request-Private-Network request by return Access-Control-Allow-Private-Network