3.8.0 • Published 1 year ago

hzb-midway-cross-domain v3.8.0

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Cross-domain 跨域组件

适用于 @midwayjs/faas@midwayjs/web@midwayjs/koa@midwayjs/express 多种框架的通用跨域组件,支持 corsjsonp 多种模式。

Usage

  1. 安装依赖
tnpm i @midwayjs/cross-domain --save
  1. 在 configuration 中引入组件,
import * as crossDomain from '@midwayjs/cross-domain';
@Configuration({
  imports: [
    // ...other components
    crossDomain
  ],
})
export class AutoConfiguration {}

CORS 配置

export const cors = {
  allowMethods: string |string[];
  origin: string|Function;
  exposeHeaders: string |string[];
  allowHeaders: string |string[];
  credentials: boolean|Function;
  keepHeadersOnError: boolean;
  maxAge: number;
}

JSONP 配置

export const jsonp = {
  callback: 'jsonp',
  limit: 512,
}