IN the frontend React Web App.
import { useState } from "react"
export default function PrestadoresServico() {
const [prestadoresServicos, setPrestadoresServicos] = useState([])
fetch('http://localhost:8080/api/prestadores-servicos').then( (response) => {
return response.json()
}).then( (dadosRetornados) => {
console.log(dadosRetornados)
} )
return (
<div><h1>Listagem Prestadores de Serviço</h1> <a href="prestador-servico/novo" >Adicionar Prestador de Serviço +</a></div>
)
}
My gateway application.yml file
spring:
application:
name: gateway
cloud:
globalcors:
corsConfigurations:
'[/**]':
allowedOrigins: "http://localhost"
allowedHeaders: "*"
allowedMethods:
- GET
- POST
- PUT
server:
port: 8080
eureka:
client:
fetch-registry: true
register-with-eureka: true
service-url:
defaultZone: http://localhost:8761/eureka
The gateway routing
package br.com.syscomercial.gateway;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
@EnableDiscoveryClient
public class GatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args);
}
@Bean
public RouteLocator routes(RouteLocatorBuilder builder){
return builder.routes().route(r -> r.path("/api/prestadores-servicos/**").uri("lb://prestadorservico"))
.route(r -> r.path("/api/avaliacoes-prestadores-servicos/**").uri("lb://avaliacaoprestadorservico")).build();
}
}