initial setup

This commit is contained in:
litoral05
2026-06-03 08:54:28 +01:00
commit b081d9c4f7
17 changed files with 752 additions and 0 deletions
@@ -0,0 +1,13 @@
package com.litoralregas.backend_gateway;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class BackendGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(BackendGatewayApplication.class, args);
}
}
@@ -0,0 +1,4 @@
package com.litoralregas.backend_gateway.client;
public class ClientEntity {
}
@@ -0,0 +1,4 @@
package com.litoralregas.backend_gateway.client;
public class ClientRepository {
}
@@ -0,0 +1,20 @@
package com.litoralregas.backend_gateway.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.SecurityFilterChain;
@Configuration
public class SecurityConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http
.csrf(csrf -> csrf.disable())
.authorizeHttpRequests(auth -> auth
.anyRequest().permitAll()
)
.build();
}
}
@@ -0,0 +1,14 @@
package com.litoralregas.backend_gateway.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.client.WebClient;
@Configuration
public class WebClientConfig {
@Bean
public WebClient webClient(WebClient.Builder builder) {
return builder.build();
}
}
@@ -0,0 +1,48 @@
package com.litoralregas.backend_gateway.gateway;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
@Service
public class BackendProxyService {
private final WebClient webClient;
private final String devBackendUrl;
public BackendProxyService(
WebClient webClient,
@Value("${gateway.dev-backend-url}") String devBackendUrl
) {
this.webClient = webClient;
this.devBackendUrl = devBackendUrl;
}
public String getHealth() {
return webClient.get()
.uri(devBackendUrl + "/actuator/health")
.retrieve()
.bodyToMono(String.class)
.block();
}
public ResponseEntity<String> proxy(HttpServletRequest request, String body) {
String path = request.getRequestURI().replaceFirst("/api/backend", "");
String query = request.getQueryString();
String targetUrl = devBackendUrl + path + (query != null ? "?" + query : "");
String response = webClient
.method(HttpMethod.valueOf(request.getMethod()))
.uri(targetUrl)
.bodyValue(body != null ? body : "")
.retrieve()
.bodyToMono(String.class)
.block();
return ResponseEntity.ok(response);
}
}
@@ -0,0 +1,31 @@
package com.litoralregas.backend_gateway.gateway;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class GatewayController {
private final BackendProxyService backendProxyService;
public GatewayController(BackendProxyService backendProxyService) {
this.backendProxyService = backendProxyService;
}
@GetMapping("/gateway/health")
public String backendHealth() {
return backendProxyService.getHealth();
}
@RequestMapping("/api/backend/**")
public ResponseEntity<String> proxy(
HttpServletRequest request,
@RequestBody(required = false) String body
) {
return backendProxyService.proxy(request, body);
}
}
@@ -0,0 +1,4 @@
package com.litoralregas.backend_gateway.user;
public class UserEntity {
}
@@ -0,0 +1,4 @@
package com.litoralregas.backend_gateway.user;
public class UserRepository {
}
+9
View File
@@ -0,0 +1,9 @@
server:
port: 18080
spring:
application:
name: backend-gateway
gateway:
dev-backend-url: http://10.100.1.2:18450
@@ -0,0 +1,13 @@
package com.litoralregas.backend_gateway;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class BackendGatewayApplicationTests {
@Test
void contextLoads() {
}
}