cors-anywhere 类型声明 types declaration

electron 中解决跨域的一个方案,在主进程中使用cros-anywhere, 起一个服务

https://github.com/Rob–W/cors-anywhere/pull/267/commits/279eaeecac9bce0476012b6510dc374f30e3663b

declare module 'cors-anywhere' {
  import { Server } from 'http';

  export function createServer(options?: Partial<{
    /**
     * If set, specifies which intermediate proxy to use for a given URL. If the return
     * value is void, a direct request is sent. The default implementation is
     * `proxy-from-env`, which respects the standard proxy environment variables (e.g.
     * `https_proxy`, `no_proxy`, etc.).
     */
    getProxyForUrl: (url: string | object) => string;

    /**
     * Maximum number of redirects to be followed.
     */
    maxRedirects: number;

    /**
     * If set, requests whose origin is listed are blocked.
     */
    originBlacklist: string[];

    /**
     * If set, requests whose origin is not listed are blocked. If this list is empty,
     * all origins are allowed.
     */
    originWhitelist: string[];

    /**
     * If set, it is called with the origin (string) of the request.
     * If this function returns a non-empty string, the request is rejected and the
     * string is send to the client.
     */
    checkRateLimit: (origin: string) => string;

    /**
     * If true, requests to URLs from the same origin will not be proxied but redirected.
     * The primary purpose for this option is to save server resources by delegating the
     * request to the client (since same-origin requests should always succeed, even
     * without proxying).
     */
    redirectSameOrigin: boolean;

    /**
     * If set, the request must include this header or the API will refuse to proxy.
     * Recommended if you want to prevent users from using the proxy for normal browsing.
     */
    requireHeader: string[];

    /**
     * Exclude certain headers from being included in the request.
     */
    removeHeaders: string[];

    /**
     * Set headers for the request (overwrites existing ones).
     */
    setHeaders: {[key: string]: string};

    /**
     * If set, an Access-Control-Max-Age header with this value (in seconds) will be added.
     */
    corsMaxAge: number;

    /**
     * Set the help file (shown at the homepage).
     */
    helpFile: string;

    /**
     * Under the hood, `http-proxy` is used to proxy requests. Use this option if you really
     * need to pass options to `http-proxy`.
     */
    httpProxyOptions: object;

    /**
     * If set, a `https.Server` will be created. The given options are passed to the
     * `https.createServer` method.
     */
    httpsOptions: object;
  }>): Server;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值