Closed bglamadrid closed 1 year ago
* This may allow some classes to be released (as in, removed from the codebase) with ease * `org.trebol.config.CorsConfigurationBuilder` * `org.trebol.config.CorsProperties`
Then the org.trebol.exceptions.CorsMappingParseException
could be removed too?
* This may allow some classes to be released (as in, removed from the codebase) with ease * `org.trebol.config.CorsConfigurationBuilder` * `org.trebol.config.CorsProperties`
Then the
org.trebol.exceptions.CorsMappingParseException
could be removed too?
That's right. That exception is only thrown within CorsConfigurationBuilder
.
Hi @bglamadrid ! I am looking at this one for a while to do next, but I have a few questions first:
Hi @mepox. Let's see. None of these questions I have the definitive, ultimate answer to. It's a matter of picking the best tradeoffs.
So for example, having all CORS configuration in the .properties
file makes it easy to update it through other means supported by Spring, such as environment variables. Plus, it's a single source of truth.
But if for any reason you decide to modify API paths e.g. changing /sales
to /orders
, then you also have to update the CORS mappings for them yourself.
On the other side, adding annotations to Controller classes and methods binds CORS mappings to the actual API paths. No need to update anything else. But you do have to know that CORS is enabled thanks to those annotations.
And annotations can be parameterized too. You should know this well since you created the PhoneNumberValidator
and its annotation 😉
Hi @bglamadrid ! Thanks for your detailed reply. 😄
On the other side, adding annotations to Controller classes and methods binds CORS mappings to the actual API paths. No need to update anything else.
This is what I was looking for, I missed it... That's explain the benefit of using this annotation. 👍 I would like to work on this issue.
Apparently I didn't know but Spring Web MVC so happens to support annotation-based CORS configuration on a per-class and per-method basis. These are then added to the default
CorsConfiguration
bean.Additional considerations
org.trebol.config.CorsConfigurationBuilder
org.trebol.config.CorsProperties
org.trebol.exceptions.CorsMappingParseException