refactor: Streamlined the API of the services
[demos/kafka/chat] / src / main / java / de / juplo / kafka / chat / backend / ChatBackendApplication.java
1 package de.juplo.kafka.chat.backend;
2
3 import de.juplo.kafka.chat.backend.domain.ChatHome;
4 import de.juplo.kafka.chat.backend.persistence.StorageStrategy;
5 import jakarta.annotation.PreDestroy;
6 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.boot.SpringApplication;
8 import org.springframework.boot.autoconfigure.SpringBootApplication;
9 import org.springframework.web.reactive.config.CorsRegistry;
10 import org.springframework.web.reactive.config.WebFluxConfigurer;
11
12
13 @SpringBootApplication
14 public class ChatBackendApplication implements WebFluxConfigurer
15 {
16         @Autowired
17         ChatBackendProperties properties;
18         @Autowired
19         ChatHome chatHome;
20         @Autowired
21         StorageStrategy storageStrategy;
22
23
24         @Override
25         public void addCorsMappings(CorsRegistry registry)
26         {
27                 registry
28                                 .addMapping("/**")
29                                 .allowedOrigins(properties.getAllowedOrigins());
30         }
31
32         @PreDestroy
33         public void onExit()
34         {
35                 storageStrategy.writeChatrooms(chatHome.list());
36         }
37
38         public static void main(String[] args)
39         {
40                 SpringApplication.run(ChatBackendApplication.class, args);
41         }
42 }