From 29f0d39a781c1924fcfbee3e4f5bcf70a48507b9 Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Wed, 18 Sep 2024 00:58:34 -0400 Subject: [PATCH] Fix CORS in prod --- .../cc/pulseapp/api/config/AppConfig.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/java/cc/pulseapp/api/config/AppConfig.java diff --git a/src/main/java/cc/pulseapp/api/config/AppConfig.java b/src/main/java/cc/pulseapp/api/config/AppConfig.java new file mode 100644 index 0000000..05d20fb --- /dev/null +++ b/src/main/java/cc/pulseapp/api/config/AppConfig.java @@ -0,0 +1,27 @@ +package cc.pulseapp.api.config; + +import lombok.NonNull; +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; + +/** + * @author Braydon + */ +@Configuration +public class AppConfig { + @Bean + public WebMvcConfigurer configureCors() { + return new WebMvcConfigurer() { + @Override + public void addCorsMappings(@NonNull CorsRegistry registry) { + // Allow all origins to access the API + registry.addMapping("/v*/**") + .allowedOrigins("*") // Allow all origins + .allowedMethods("*") // Allow all methods + .allowedHeaders("*"); // Allow all headers + } + }; + } +}