-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[] chatHomes;
+ @Autowired
+ StorageStrategy storageStrategy;
+
+
+ @Override
+ public void addCorsMappings(CorsRegistry registry)
{
- return Clock.systemDefaultZone();
+ registry
+ .addMapping("/**")
+ .allowedOrigins(properties.getAllowedOrigins());
}
+ @PreDestroy
+ public void onExit()
+ {
+ for (int shard = 0; shard < chatHomes.length; shard++)
+ storageStrategy.write(chatHomes[shard].getChatRooms());
+ }
public static void main(String[] args)
{
- SpringApplication.run(ChatroomApplication.class, args);
+ SpringApplication.run(ChatBackendApplication.class, args);
}
}