refactor: Streamlined the API of the services
[demos/kafka/chat] / src / main / java / de / juplo / kafka / chat / backend / ChatBackendApplication.java
index 37eeeee..f98a02a 100644 (file)
@@ -6,22 +6,33 @@ import jakarta.annotation.PreDestroy;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.context.annotation.Bean;
-import reactor.core.publisher.Flux;
+import org.springframework.web.reactive.config.CorsRegistry;
+import org.springframework.web.reactive.config.WebFluxConfigurer;
 
 
 @SpringBootApplication
-public class ChatBackendApplication
+public class ChatBackendApplication implements WebFluxConfigurer
 {
+       @Autowired
+       ChatBackendProperties properties;
        @Autowired
        ChatHome chatHome;
        @Autowired
        StorageStrategy storageStrategy;
 
+
+       @Override
+       public void addCorsMappings(CorsRegistry registry)
+       {
+               registry
+                               .addMapping("/**")
+                               .allowedOrigins(properties.getAllowedOrigins());
+       }
+
        @PreDestroy
        public void onExit()
        {
-               storageStrategy.writeChatrooms(Flux.fromIterable(chatHome.list()));
+               storageStrategy.writeChatrooms(chatHome.list());
        }
 
        public static void main(String[] args)