fakeheal/cors-anywhere

cors-anywhere 是一个 PHP 反向代理,它会在代理请求中添加 CORS 头部。

v0.0.4 2023-06-15 11:37 UTC

This package is auto-updated.

Last update: 2024-09-15 16:51:44 UTC


README

Tests Latest Stable Version Total Downloads License PHP Version Require

cors-anywhere 是一个 PHP 反向代理,它会在代理请求中添加 CORS 头部。

用例

当无法在目标网站上启用 CORS 时,它可以用来访问第三方网站的资源,例如,当你不拥有该网站时。

作者的话: 我目前正在用它来访问 Rescue Timetrak.tv 的 API,以便将我的数据同步到 conjure.so

文档

安装

composer require fakeheal/cors-anywhere

初始化

<?php

use Fakeheal\CorsAnywhere\Exceptions\CorsAnywhereException;
use Fakeheal\CorsAnywhere\Proxy;

// ...

try {
    $server = new Proxy([
        // allowed hosts to proxy to
        'rescuetime.com',
        'google.com'
    ], [
        // allowed headers
        'Content-Type',
        'Accepts'    
    ]);

    // call handle that... handles everything
    $server->handle();
} catch (CorsAnywhereException $e) {
    die($e->getMessage()); // or die trying
}

致谢

运行测试

要运行测试,请执行以下命令

  ./vendor/bin/pest

使用情况

此项目被以下实体使用

许可证

MIT