fruitcake / laravel-cors

Adds CORS (Cross-Origin Resource Sharing) headers support in your Laravel application
MIT License
6.27k stars 616 forks source link

v2.1.0 it's a breaking change #557

Closed route33 closed 2 years ago

route33 commented 2 years ago

The upgrade from v2.0.5 to v2.1.0 is a BC for users that call Asm89\Stack\CorsService dependency, for custom/dynamic settings.

This change should have been marked as major.

Laravel: 8.83.1 FruitCake: 2.1.0 PHP: 8.1.2

barryvdh commented 2 years ago

How are you extending this exactly? This wasn't really a supported use case.

barryvdh commented 2 years ago

I don't think the you have the options to change any configuration at runtime right? So you're just replacing the CorsService directly?

barryvdh commented 2 years ago

I could release https://github.com/fruitcake/laravel-cors/pull/558 as v2.2.0 and tagged the current 2.1 as 3.0 🤔

route33 commented 2 years ago
use Fruitcake\Cors\CorsServiceProvider as ParentCorsServiceProvider;
use Asm89\Stack\CorsService;

class CorsServiceProvider extends ParentCorsServiceProvider
{
    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $this->mergeConfigFrom($this->configPath(), 'cors');

        $this->app->scoped(CorsService::class, function () {
            return new CorsService($this->customCorsOptions());
        });
    }

    /**
     * Get options for CorsService
     *
     * @return array
     */
    protected function customCorsOptions(): array
    {
        $options = $this->corsOptions();

        $options['allowedOrigins'] = static::allowedOrigins();

        return $options;
    }

    protected static function allowedOrigins(): array
    {
        $hosts = Cache::rememberForever('sites', function () {
        ...
        });

        return $hosts;
    }
}    
barryvdh commented 2 years ago

I've tagged 2.2.0 with the original namespace. Will prepare 3.x with the new one.

pathros commented 2 years ago

@barryvdh From composer outdated

  • major release available - update possible,

I see there's a new mayor release of fruitcake/laravel-cors.

I am using Laravel 9. Is the v.3.0.0 supported?

If so, How do I upgrade it?

barryvdh commented 2 years ago

With Laravel 9, you can use the built in CORS, see Laravel/laravel