Added corsConfig + systemInfo controller

This commit is contained in:
litoral05
2026-05-20 12:23:23 +01:00
parent 809b79b6f6
commit 315f7b61f8
4 changed files with 69 additions and 0 deletions
@@ -0,0 +1,23 @@
package com.litoralregas.backend.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class CorsConfig {
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/api/**")
.allowedOrigins("http://localhost:1420")
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowedHeaders("*");
}
};
}
}
@@ -0,0 +1,9 @@
package com.litoralregas.backend.system;
public record RuntimeConfigResponse(
String mode,
String controllerName,
String controllerIp,
Integer backendPort
) {
}
@@ -0,0 +1,32 @@
package com.litoralregas.backend.system;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/system")
public class SystemRuntimeController {
@Value("${litoralregas.modbus.host}")
private String controllerIp;
@Value("${server.port}")
private Integer backendPort;
@Value("${litoralregas.runtime.mode}")
private String mode;
@Value("${litoralregas.runtime.controller-name}")
private String controllerName;
@GetMapping("/runtime-config")
public RuntimeConfigResponse getRuntimeConfig() {
return new RuntimeConfigResponse(
mode,
controllerName,
controllerIp,
backendPort
);
}
}
+5
View File
@@ -1,3 +1,5 @@
server:
port: 18450
spring:
application:
name: backend
@@ -16,6 +18,9 @@ spring:
locations: classpath:db/migration
litoralregas:
runtime:
mode: Local
controller-name: Estufa_Litoral
modbus:
host: 198.19.0.176
port: 533