1 Star 2 Fork 1

赵先生 / think-cors

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

think-cors

用于解决前后端分离时tp6的跨域问题

安装

composer require qiansion/think-cors

配置

安装完毕后会自动生成配置文件config/cors.php

<?php
return [

    //允许的域名
    'allow_origin' => [
        '*'
    ],

    //允许的请求头
    "allow_headers" => [
        'Origin',
        'X-Requested-With',
        'Content-Type',
        'Accept',
        'Authorization'
    ],

    //允许的方法
    "allow_methods" => [
        'GET',
        'POST',
        'PUT',
        'DELETE',
        'OPTIONS',
        'PATCH'
    ]
];

使用

think-cors功能默认是没有开启的,如果你需要使用think-cors,需要在全局的中间件定义文件中加上下面的中间件定义:

\qiansion\middleware\Cors::class

Tips:如果是多应用模式,并且你只是用于部分应用,那么也可以在应用中间件定义文件中单独开启

MIT License Copyright (c) 2022 赵先生 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

用于解决前后端分离时thinkphp的跨域问题 展开 收起
PHP
MIT
取消

贡献者

全部

近期动态

加载更多
不能加载更多了
PHP
1
https://gitee.com/qiansion/think-cors.git
git@gitee.com:qiansion/think-cors.git
qiansion
think-cors
think-cors
master

搜索帮助