From b52128c35c26fb99cb7b79fbf48f4711ece854ec Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 8 Feb 2024 00:02:11 +0100 Subject: [PATCH] Added deployment modes - CORS only apply in dev mode --- .../de/w665/sharepulse/config/CorsConfig.java | 22 +++++++++++++++++++ src/main/resources/application.properties | 3 +++ 2 files changed, 25 insertions(+) create mode 100644 src/main/java/de/w665/sharepulse/config/CorsConfig.java diff --git a/src/main/java/de/w665/sharepulse/config/CorsConfig.java b/src/main/java/de/w665/sharepulse/config/CorsConfig.java new file mode 100644 index 0000000..e9f9fb6 --- /dev/null +++ b/src/main/java/de/w665/sharepulse/config/CorsConfig.java @@ -0,0 +1,22 @@ +package de.w665.sharepulse.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +@Profile("development") +public class CorsConfig implements WebMvcConfigurer { + + // NEVER LEAVE THIS CONFIGURATION IN PRODUCTION + @Override + public void addCorsMappings(CorsRegistry registry) { + System.out.println("CORS CONFIGURATION ENABLED | DEVELOPMENT PROFILE"); + System.out.println("IF YOU SEE THIS MESSAGE IN PRODUCTION, PLEASE DISABLE DEVELOPEMENT MODE IN APPLICATION.PROPERTIES"); + registry.addMapping("/api/v1/speed-test") + .allowedOrigins("*") + .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") + .allowedHeaders("*"); + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 05b0892..ce36a92 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -22,3 +22,6 @@ rethinkdb.database=sharepulse # Miscellaneous server.port=80 spring.application.name=sharepulse + +# Spring profiles (Options: development, production) (Controls cors) +spring.profiles.active=development \ No newline at end of file