定制 ajiho/think-cors 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ajiho/think-cors

最新稳定版本:V1.0.3

Composer 安装命令:

composer require ajiho/think-cors

包简介

cors middleware for thinkphp6

README 文档

README

是一个用于解决前后端分离thinkphp6输出API时产生跨域问题的简单中间件。

安装

composer require ajiho/think-cors

优点

虽然代码量不多,而且也很简单,抽离出来通过composer方式安装,通过配置文件的方式解决跨域问题变得很简单,多个项目也能复用,同时后期维护也比较简单。

配置

/config/cors.php

<?php
return [

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

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

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

使用

和tp6的中间件用法一样

\ajiho\middleware\Cors::class

统计信息

  • 总下载量: 214
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-15