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.fromIterable(chatHome.list()));
+ for (int shard = 0; shard < chatHomes.length; shard++)
+ storageStrategy.write(chatHomes[shard].getChatRooms());
}
public static void main(String[] args)