CORS Config
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m26s

This commit is contained in:
Braydon 2024-04-11 08:16:12 -04:00
parent 6993fe6681
commit 63121afe32

@ -38,6 +38,8 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.info.BuildProperties; import org.springframework.boot.info.BuildProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/** /**
* The configuration for the app. * The configuration for the app.
@ -88,4 +90,23 @@ public class AppConfig {
.info(info) .info(info)
.addServersItem(new Server().url(serverPublicUrl).description("The public server URL")); .addServersItem(new Server().url(serverPublicUrl).description("The public server URL"));
} }
/**
* Configure CORS for the app.
*
* @return the WebMvc config
*/
@Bean @NonNull
public WebMvcConfigurer configureCors() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(@NonNull CorsRegistry registry) {
// Allow all origins to access the API
registry.addMapping("/**")
.allowedOrigins("*") // Allow all origins
.allowedMethods("*") // Allow all methods
.allowedHeaders("*"); // Allow all headers
}
};
}
} }