From 4a5a2216051547c810e5a5be313d405d933b163e Mon Sep 17 00:00:00 2001 From: Mattrixwv Date: Sat, 27 Apr 2024 16:23:05 -0400 Subject: [PATCH] Updated CORS to use a property --- .../cipherstream/config/WebConfig.java | 7 ++++- ...itional-spring-configuration-metadata.json | 27 +++++++++++++++++++ src/main/resources/application.properties | 1 + 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/META-INF/additional-spring-configuration-metadata.json diff --git a/src/main/java/com/mattrixwv/cipherstream/config/WebConfig.java b/src/main/java/com/mattrixwv/cipherstream/config/WebConfig.java index cc7c2ee..08a8d0d 100644 --- a/src/main/java/com/mattrixwv/cipherstream/config/WebConfig.java +++ b/src/main/java/com/mattrixwv/cipherstream/config/WebConfig.java @@ -1,6 +1,7 @@ package com.mattrixwv.cipherstream.config; +import org.springframework.beans.factory.annotation.Value; import org.springframework.lang.NonNull; import org.springframework.stereotype.Component; import org.springframework.web.servlet.config.annotation.CorsRegistry; @@ -11,9 +12,13 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Component @EnableWebMvc public class WebConfig implements WebMvcConfigurer{ + @Value("${allowedOrigins}") + private String allowedOrigins; + + @Override public void addCorsMappings(@NonNull CorsRegistry registry){ registry.addMapping("/**") - .allowedOriginPatterns("http://localhost:3000"); + .allowedOriginPatterns(allowedOrigins); } } diff --git a/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/src/main/resources/META-INF/additional-spring-configuration-metadata.json new file mode 100644 index 0000000..f9d9aa9 --- /dev/null +++ b/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -0,0 +1,27 @@ +{ + "groups":[ + ], + "properties":[ + { + "name": "allowed-origins", + "type": "java.lang.String", + "description": "Allowed CORS origins", + "defaultValue": "http://localhost:3000" + } + ], + "hints":[ + { + "name": "allowed-origins", + "values": [ + { + "value": "http://localhost:3000", + "description": "Local development" + }, + { + "value": "https://api.cipherstream.mattrixwv.com", + "description": "Production" + } + ] + } + ] +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index ebc64e2..63c0dc3 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1,2 @@ server.port=8001 +allowedOrigins=http://localhost:3000