phalapi/cors

PhalApi 2.x 扩展类库 - 跨域

dev-master 2018-11-27 06:33 UTC

This package is not auto-updated.

Last update: 2024-11-18 16:15:44 UTC


README

安装和配置

修改项目下的composer.json文件,并添加:

    "phalapi/cors":"dev-master"

在/path/to/phalapi/config/app.php文件中,配置:

    'cors' => array(
        //域名白名单
        'whitelist'   => array(
            //'http://xxx.xx.xxx',
            //'http://xxx.xxx.xxx'
        ),  
        //header头
        'headers' => array(
            'Access-Control-Allow-Methods' => 'GET, POST, PUT, DELETE, OPTIONS', //支持的请求类型
            'Access-Control-Allow-Credentials' => 'true' //支持cookie
        )
    )

然后执行composer update

注册

在/path/to/phalapi/config/di.php文件中,注册:

$di->cors = new \PhalApi\CORS\Lite();