Added deployment modes

- CORS only apply in dev mode
This commit is contained in:
Max W. 2024-02-08 00:02:11 +01:00
parent a864d81bef
commit b52128c35c
2 changed files with 25 additions and 0 deletions

View File

@ -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("*");
}
}

View File

@ -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