nelmio / NelmioCorsBundle

Adds CORS (Cross-Origin Resource Sharing) headers support in your Symfony application
https://symfony.com/bundles/NelmioCorsBundle/
MIT License
1.89k stars 108 forks source link

Automatic rule extraction based on routing. #60

Closed Padam87 closed 1 year ago

Padam87 commented 8 years ago

Hi,

I've created a small addition which automatically extracts methods from the routing, because I always forget to update the config.

I think the bundle should have a feature like this (in an opt-in version of course).

https://gist.github.com/Padam87/ad4434502de71e32626fbb4daa7f1b47

If its okay, i will submit a PR. Alernatively, we could create a command which dumps the path rules to yaml.

Seldaek commented 8 years ago

I am not quite sure I understand what this is supposed to do. Can you explain a little more?

Padam87 commented 8 years ago

Instead of you having to specify the paths, this one does it automatically by going through the route collection.

For example if you have two routes for the /user/{id} url, it merges the methods used into an array.

It will end up almost as the same as the path collection you can specify in yml. You can check it in the gist, the cors.cache.php file is dumped by the cache warmer.

Then the config provider reads the rules...

The priority of this provider is 1, so the yml config takes precedence.

Seldaek commented 8 years ago

OK but.. is it automatically mapping all routes to allow cors on them? If so why not just allow all URLs in the config and be done with it?

Padam87 commented 8 years ago

This is specific. Exact methods for every route.

Seldaek commented 8 years ago

OK I see. Would be good to combine this with #43 to do it only for annotated routes and then it'd be quite powerful I think.

Seldaek commented 1 year ago

Closing as it seems nobody had any interest in pushing this further.