定制 adoranwodo/laravelcorsmiddleware 二次开发

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

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

adoranwodo/laravelcorsmiddleware

Composer 安装命令:

composer require adoranwodo/laravelcorsmiddleware

包简介

Add CORS support to your Lumen / Laravel application

README 文档

README

Latest Version on Packagist Total Downloads Build Status License composer.lock available

Laravel Cors Middleware is a package that allows users enable Cross-Origin Resource Sharing (CORS) for their Laravel / Lumen applications by taking advantage of the middleware configuration.

Installation

Via Composer

$ composer require adoranwodo/laravelcorsmiddleware

Usage

Laravel

If you are using Laravel, please continue here. If you are using Lumen, please scroll down to the Lumen section.

Configuration

Please add the service provider to your config/app.php :

'providers' => [
  ...
  AdoraNwodo\LaravelCorsMiddleware\LaravelCorsMiddlewareServiceProvider::class
]

There is a default configuration in config/laravelcorsmiddleware.php. Publish this file to your own config directory and change to your own values. You can publish the file by running the code below in your terminal:

php artisan vendor:publish --provider="AdoraNwodo\LaravelCorsMiddleware\LaravelCorsMiddlewareServiceProvider"

There are some instructions in the config. Please adhere strictly and you should be fine :).

Finally, you need to add this to your middleware. You can add it globally or to a middleware group.

Global Middleware (Laravel)

To use the CORS middleware globally (on all routes), go to app/Http/Kernel.php and add the laravelcorsmiddleware to your $middleware array like this:

protected $middleware = [
  ...
  \AdoraNwodo\LaravelCorsMiddleware\LaravelCorsMiddleware::class,
]

Middleware Group (Laravel)

To use the CORS middleware only for specific routes or groups, go to app/Http/Kernel.php and add the laravelcorsmiddleware to your middleware group array like this:

protected $middlewareGroups = [
    'web' => [
        ...
        \AdoraNwodo\LaravelCorsMiddleware\LaravelCorsMiddleware::class,
    ],

    'api' => [
        ...
    ],
];

Lumen

If you are using Lumen, please continue here. If you are using Laravel, please scroll up to the Laravel section

Configuration

Please create a /config directory in the parent directory and add create a new laravelcorsmiddleware.php file. Paste this into your new php file (You can edit the values as you like).

<?php

return [
    
    /*
	*  __________      __________       ___________     __________
	* |               |          |     |           |   |
	* |               |          |     |           |   |
	* |               |          |     |           |   |
	* |               |          |     |___________|   |__________
	* |               |          |     |       \                  |
	* |               |          |     |        \                 |
	* |               |          |     |         \                |
	* |__________     |__________|     |          \    ___________|
	*
	*
	*
	* LARAVEL CORS MIDDLEWARE
	* 
	* Please add a list of values to allowedOrigins, allowedMethods and allowedHeaders. 
	* You can also choose to set the value of these to '*', but note that this is not advisable 
	* for allowedOrigins as this would give everyone access to your api.
    */

    'allowCredentials' => true,		//true or false.      NOTE: Boolean NOT String. 'true' is different from true
    'allowedOrigins' => ['*'],        	//array of strings    e.g. ['*'] or ['https://mywebsite.com', 'https://anotherwebsite.com', ... ]
    'allowedMethods' => ['*'],    	//array of strings    e.g. ['*'] or ['GET', 'POST', ... ]
    'allowedHeaders' => ['*'],          //array of strings.   e.g. ['*'] or ['Content-Type', 'Authorization', ... ]
    'maxAge' => 86400,                	//number.             e.g. 86400
];

Once this is done, you can go to bootstrap/app.php. Here, you will load the configuration file manually and register the service provider like this:

$app->configure('laravelcorsmiddleware');  //load the config file
$app->register(AdoraNwodo\LaravelCorsMiddleware\LaravelCorsMiddlewareServiceProvider::class);  //register the service provider

Finally, you need to add this to your middleware. You can add it globally or to a middleware group.

Global Middleware (Lumen)

To use the CORS middleware globally (on all routes), go to bootstrap/app.php and add the laravelcorsmiddleware to your $middleware array like this:

$app->middleware([
  ...
  \AdoraNwodo\LaravelCorsMiddleware\LaravelCorsMiddleware::class,
]);

Middleware Group (Lumen)

To use the CORS middleware only for specific routes or groups, go to bootstrap/app.php and add the laravelcorsmiddleware to your middleware group array like this:

$app->routeMiddleware([
    'cors' => \AdoraNwodo\LaravelCorsMiddleware\LaravelCorsMiddleware::class
]);

Change log

Please see the changelog for more information on what has changed recently.

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email nennenwodo@gmail.com instead of using the issue tracker.

License

osl 3.0. Please see the license file for more information.

adoranwodo/laravelcorsmiddleware 适用场景与选型建议

adoranwodo/laravelcorsmiddleware 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 26 次下载、GitHub Stars 达 3, 最近一次更新时间为 2018 年 11 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「LaravelCorsMiddleware」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 adoranwodo/laravelcorsmiddleware 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 adoranwodo/laravelcorsmiddleware 我们能提供哪些服务?
定制开发 / 二次开发

基于 adoranwodo/laravelcorsmiddleware 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: osl-3.0
  • 更新时间: 2018-11-01