From 63121afe3253cf73e8a57694125314cf638b9d37 Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Thu, 11 Apr 2024 08:16:12 -0400 Subject: [PATCH] CORS Config --- .../java/me/braydon/mc/config/AppConfig.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/me/braydon/mc/config/AppConfig.java b/src/main/java/me/braydon/mc/config/AppConfig.java index 4631a22..df353e5 100644 --- a/src/main/java/me/braydon/mc/config/AppConfig.java +++ b/src/main/java/me/braydon/mc/config/AppConfig.java @@ -38,6 +38,8 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.info.BuildProperties; import org.springframework.context.annotation.Bean; 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. @@ -88,4 +90,23 @@ public class AppConfig { .info(info) .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 + } + }; + } } \ No newline at end of file