fakeheal / cors-anywhere
cors-anywhere 是一个 PHP 反向代理,它会在代理请求中添加 CORS 头部。
v0.0.4
2023-06-15 11:37 UTC
Requires
- php: ^8.2
- guzzlehttp/guzzle: ^7.0
- symfony/http-foundation: ^6.0
Requires (Dev)
- pestphp/pest: 2.x-dev
- phpstan/phpstan: 1.11.x-dev
- rector/rector: ^0.17.1
README
cors-anywhere
是一个 PHP 反向代理,它会在代理请求中添加 CORS 头部。
用例
当无法在目标网站上启用 CORS 时,它可以用来访问第三方网站的资源,例如,当你不拥有该网站时。
作者的话: 我目前正在用它来访问 Rescue Time 和 trak.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
使用情况
此项目被以下实体使用