jkirkby91 / lumenpsr7cors
此包已弃用,不再维护。未建议替代包。
此包的最新版本(1.1.0)没有可用的许可信息。
1.1.0
2017-12-07 05:20 UTC
Requires
- psr/http-message: ^1.0
- zendframework/zend-diactoros: ^1.3
Requires (Dev)
- phpunit/phpunit: 4.*
This package is not auto-updated.
Last update: 2021-01-19 07:23:56 UTC
README
安装
按照 Lumen 文档 安装 lumen 后,从 lumen
文件夹安装 lumen-cors。
使用 Composer 安装
运行 composer require "Jkirkby91-2/LumenPSR7Cors"
安装 lumen-cors。
使用方法
全局 CORS
如果希望应用程序的每个 HTTP 请求都启用 CORS,只需在 bootstrap/app.php
文件的 $app->middleware() 调用中列出中间件类 Jkirkby91\LumenPSR7Cors\Http\Middleware\Cors
。
路由的 CORS
如果想要为特定路由启用 CORS,首先应在 bootstrap/app.php
文件中为 lumen-cors
中间件分配一个简写键。
$app->routeMiddleware([ 'cors' => 'Jkirkby91\LumenPSR7Cors\Http\Middleware\Cors', ]);
然后,在路由选项数组中使用该键。
$app->get('/data', ['middleware' => 'cors', function() { // }]);
更多信息 - http://lumen.laravel.com/docs/middleware#registering-middleware