reezy/cors

reezy cors

Maintainers

Details

gitee.com/ezy/cors

v0.1.0 2020-10-15 10:31 UTC

This package is not auto-updated.

Last update: 2024-05-11 03:34:14 UTC


README

支持PHP-PSR规范的跨域资源共享(cors)中间件。

安装依赖

composer require reezy/cors 

配置

<?php

return [
    // 是否允许所有的域
    'allowed-all-origins'   => env('APP_ENV') !== 'prod',
    // 允许访问该资源的域
    'allowed-origins'       => ['http://localhost'],
    // 实际请求中允许携带的所有首部字段
    'allowed-headers'       => ['authorization', 'content-type', 'x-requested-with'],
    // 实际请求中允许使用的所有HTTP方法
    'allowed-methods'       => ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], // ex: GET, POST, PUT, PATCH, DELETE
    // 实际的请求是否可以使用credentials
    'allowed-credentials'   => true,
    // 白名单,列出了服务器允许浏览器访问的头
    // 六种简单首部不需要指定:Cache-Control, Content-Language, Content-Type, Expires, Last-Modified, Pragma
    'exposed-headers'       => [ ],
    // 预检请求的结果能够被缓存多久,单位秒
    'max-age'               => 10 * 86400,
];

LICENSE

The Component is open-sourced software licensed under the Apache license.