YK mar
YK mar

Reputation: 677

Spring Cloud Gateway routing doesn't work

I'm using Spring Cloud(Hoxton.SR10) with Spring Boot (2.2.6.RELEASE)

I registre my services in Eureka server 8761

and I have a gateway-service to manage routing (without any security for the moment)

# profil DEV
---
spring:
  profiles: dev

  cloud:
    gateway:
      routes:
        - id: pr-api-id
          uri: http://localhost:8086/
          predicates:
           - Path=/api/**

and this is the pom.xml

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-actuator</artifactId>
</dependency>
<!-- Spring cloud eureka client -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

when I call localhost:9092/api/v0 (I have a service on localhost:8086/v0 that working fine) should return me the same result of localhost:8086/v0 du to the routing of spring cloud gateway

but I got http error 404

This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Sep 27 12:46:20 CEST 2021
There was an unexpected error (type=Not Found, status=404).
No message available

gateway mainClass java

@SpringBootApplication
@EnableEurekaClient
public class GatewayApplication {

Upvotes: 0

Views: 1626

Answers (1)

YK mar
YK mar

Reputation: 677

I finally resolve my problem by adding the cors-configuration in my config file.

spring:
   cloud:
          gateway:
      default-filters:
        - DedupeResponseHeader=Access-Control-Allow-Origin
      globalcors:
        cors-configurations:
          "[/**]":
            allowCredentials: true
            allowedOrigins: "*"
            allowedHeaders: "Origin, X-Requested-With, Content-Type, Accept, Content-Length, TOKEN, Authorization"
            allowedMethods: "GET, POST, PATCH, PUT, DELETE, OPTIONS"
            maxAge: 3628800

Upvotes: 0

Related Questions