Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue Title: Replace CORSFilter with WebMvcConfigurer for CORS configuration #3

Open
NWOM opened this issue Mar 13, 2024 · 0 comments

Comments

@NWOM
Copy link

NWOM commented Mar 13, 2024

We currently have a CORS filter (CORSFilter) in our codebase to handle Cross-Origin Resource Sharing. However, there is a more modern and Spring-centric approach using WebMvcConfigurer. This issue aims to replace the existing CORSFilter with the WebMvcConfigurer-based configuration.

PROPOSED CHANGES
Replace the existing CORSFILTER.java class under config with the following configurtaion in DatabaseConfiguration.java

@Bean
public WebMvcConfigurer corsConfigurer() {
    return new WebMvcConfigurer() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**")
                    .allowedOrigins("*")
                    .allowedMethods("*")
                    .allowedHeaders("*")
                    .allowCredentials(false).maxAge(3600);
        }
    };
}

This approach is more in line with modern Spring practices and provides a concise and effective way to handle CORS globally in our Spring Boot application and thereby reduces the boilerplate code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant