WIP
[demos/kafka/chat] / src / main / java / de / juplo / kafka / chat / backend / ChatBackendApplication.java
index 0700496..8e1ff9e 100644 (file)
@@ -6,22 +6,34 @@ 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
-       ChatHome chatHome;
+       ChatBackendProperties properties;
+       @Autowired
+       ChatHome[] chatHomes;
        @Autowired
        StorageStrategy storageStrategy;
 
+
+       @Override
+       public void addCorsMappings(CorsRegistry registry)
+       {
+               registry
+                               .addMapping("/**")
+                               .allowedOrigins(properties.getAllowedOrigins());
+       }
+
        @PreDestroy
        public void onExit()
        {
-               storageStrategy.writeChatrooms(Flux.fromStream(chatHome.list()));
+               for (int shard = 0; shard < chatHomes.length; shard++)
+                       storageStrategy.write(chatHomes[shard].getChatRooms());
        }
 
        public static void main(String[] args)