From a4a29cfa206826277b700edc1cf7403503ad2560 Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 23 Apr 2024 02:04:56 +0100 Subject: [PATCH] add cors --- .../cc/fascinated/backend/config/Config.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/main/java/cc/fascinated/backend/config/Config.java diff --git a/src/main/java/cc/fascinated/backend/config/Config.java b/src/main/java/cc/fascinated/backend/config/Config.java new file mode 100644 index 0000000..2789a77 --- /dev/null +++ b/src/main/java/cc/fascinated/backend/config/Config.java @@ -0,0 +1,25 @@ +package cc.fascinated.backend.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; + +@Configuration +public class Config { + + @Bean + 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 + } + }; + } +}