papimod/cors
最新稳定版本:v2.1.0
Composer 安装命令:
composer require papimod/cors
包简介
Module Papi
README 文档
README
Description
Help setting up cross-origin resource sharing in your papi.
This module is based on the official tutorial.
Prerequisites Modules
Configuration
CORS_ORIGIN (.ENV)
| Required | No |
| Type | string |
| Description | Set Access-Control-Allow-Origin |
| Default | * |
CORS_METHODS (.ENV)
| Required | No |
| Type | string |
| Description | Set Access-Control-Allow-Methods |
| Default | GET, POST, PUT, PATCH, DELETE, OPTIONS |
CORS_MAX_AGE (.ENV)
| Required | No |
| Type | string |
| Description | Set Access-Control-Max-Age |
| Default | 3600 |
CORS_HEADERS (.ENV)
| Required | No |
| Type | string |
| Description | Set Access-Control-Allow-Headers |
| Default | * |
CORS_EXPOSE_HEADERS (.ENV)
| Required | No |
| Type | string |
| Description | Set Access-Control-Expose-Headers |
| Default | * |
Usage
You can add the following options to your .env file:
CORS_PRIORITY=1 CORS_ORIGIN=plop.fr CORS_HEADERS="Content-Type, x-requested-with" CORS_EXPOSE_HEADERS="Content-Encoding, Foo-Bar" CORS_METHODS="GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD"
Import the module when creating your application:
require __DIR__ . "/../vendor/autoload.php"; use Papi\PapiBuilder; use Papimod\Dotenv\DotEnvModule; use Papimod\Common\CommonModule; use Papimod\HttpError\HttpErrorModule; use Papimod\Cors\CorsModule; use function DI\create; $builder = new PapiBuilder(); $builder ->setModule( DotEnvModule::class, # Prerequisite CommonModule::class, # Prerequisite of HttpErrorModule HttpErrorModule::class, # Prerequisite CorsModule::class ) ->build() ->run();
MDN Recommendations
-
The server must not specify the
*wildcard for theAccess-Control-Allow-Originresponse-header value, but must instead specify an explicit origin; for example:Access-Control-Allow-Origin: https://example.com -
The server must not specify the
*wildcard for theAccess-Control-Allow-Headersresponse-header value, but must instead specify an explicit list of header names; for example,Access-Control-Allow-Headers: X-PINGOTHER, Content-Type -
The server must not specify the
*wildcard for theAccess-Control-Allow-Methodsresponse-header value, but must instead specify an explicit list of method names; for example,Access-Control-Allow-Methods: POST, GET -
The server must not specify the
*wildcard for theAccess-Control-Expose-Headersresponse-header value, but must instead specify an explicit list of header names; for example,Access-Control-Expose-Headers: Content-Encoding, Kuma-Revision
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2025-12-08