Skip to content

Commit

Permalink
fix CORS - add Cors filter
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Jareš <[email protected]>
  • Loading branch information
pj892031 committed Jan 17, 2025
1 parent c3f4856 commit ba2ed3c
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@
import org.springframework.context.annotation.Primary;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.util.CollectionUtils;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.server.WebFilter;
import org.springframework.web.util.UriComponentsBuilder;
import org.springframework.web.util.pattern.PathPatternParser;
import org.zowe.apiml.config.AdditionalRegistration;
Expand Down Expand Up @@ -433,6 +435,28 @@ public CorsUtils corsUtils() {
return new CorsUtils(corsEnabled, null);
}

@Bean
public WebFilter corsWebFilter(CorsConfigurationWrapper corsConfigurationWrapper) {
AtomicReference<WebFilter> webFilter = new AtomicReference<>();
return (exchange, chain) -> {
if (corsConfigurationWrapper.isReady()) {
var filter = webFilter.get();
if (filter == null) {
synchronized (this) {
if (webFilter.get() == null) {
var newFilter = new CorsWebFilter(corsConfigurationWrapper.getCorsConfigurationSource());
webFilter.set(newFilter);
filter = newFilter;
}
}
}
return filter.filter(exchange, chain);

}
return chain.filter(exchange);
};
}

public InstanceInfo create(EurekaInstanceConfig config) {
LeaseInfo.Builder leaseInfoBuilder = LeaseInfo.Builder.newBuilder()
.setRenewalIntervalInSecs(config.getLeaseRenewalIntervalInSeconds())
Expand Down

0 comments on commit ba2ed3c

Please sign in to comment.