Skip to content

Instantly share code, notes, and snippets.

@walidum
Created May 5, 2021 13:16
Show Gist options
  • Save walidum/cef8a4cc6eaef2d8d85de22ec2034c81 to your computer and use it in GitHub Desktop.
Save walidum/cef8a4cc6eaef2d8d85de22ec2034c81 to your computer and use it in GitHub Desktop.
To enable CORS in the WebFlux Java configuration, you can use the CorsRegistry callback, as the following example shows:
@Configuration
@EnableWebFlux
public class WebConfig implements WebFluxConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/api/**")
.allowedOrigins("https://domain2.com")
.allowedMethods("PUT", "DELETE")
.allowedHeaders("header1", "header2", "header3")
.exposedHeaders("header1", "header2")
.allowCredentials(true).maxAge(3600);
// Add more mappings...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment