refactor: Streamlined the API of the services
[demos/kafka/chat] / src / main / java / de / juplo / kafka / chat / backend / ChatBackendApplication.java
index 287c9ee..f98a02a 100644 (file)
@@ -1,24 +1,42 @@
-package de.juplo.kafka.chatroom;
+package de.juplo.kafka.chat.backend;
 
+import de.juplo.kafka.chat.backend.domain.ChatHome;
+import de.juplo.kafka.chat.backend.persistence.StorageStrategy;
+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 java.time.Clock;
+import org.springframework.web.reactive.config.CorsRegistry;
+import org.springframework.web.reactive.config.WebFluxConfigurer;
 
 
 @SpringBootApplication
-public class ChatroomApplication
+public class ChatBackendApplication implements WebFluxConfigurer
 {
-       @Bean
-       public Clock clock()
+       @Autowired
+       ChatBackendProperties properties;
+       @Autowired
+       ChatHome chatHome;
+       @Autowired
+       StorageStrategy storageStrategy;
+
+
+       @Override
+       public void addCorsMappings(CorsRegistry registry)
        {
-               return Clock.systemDefaultZone();
+               registry
+                               .addMapping("/**")
+                               .allowedOrigins(properties.getAllowedOrigins());
        }
 
+       @PreDestroy
+       public void onExit()
+       {
+               storageStrategy.writeChatrooms(chatHome.list());
+       }
 
        public static void main(String[] args)
        {
-               SpringApplication.run(ChatroomApplication.class, args);
+               SpringApplication.run(ChatBackendApplication.class, args);
        }
 }