Solution to the problem of using Alibaba gateway but unable to route successfully

One of the important functions of gateway is routing and forwarding. We often encounter the problem of forwarding failure
for example, the front-end configuration is as follows:

 // api interface request address
 window.SITE_CONFIG['baseUrl'] = 'http://localhost:90/api';

The application.yml configuration of gateway is as follows:

server:
  port: 90
spring:
  application:
    name: threat-gateway
  cloud:
    gateway:
      routes:
#        threat-ip microservice routing and forwarding
        - id: ip_route
# The forwarding address of the matching route
          uri: lb://threat-ip
          predicates:
            - Path=/api/cyber_threat_ip/**
          filters:
            - RewritePath=/api/(?<segment>.*),/$\{segment}

The reason for the error may be that the registry (such as Nacos) is not enabled, resulting in the unrecognized name of the microservice
it is revised as follows:

#          Match the forwarding address of the route (8082 is the threat-ip microservice port)
          uri: localhost:8082

As a result, an error was reported because http://, should be added in front of the URI, as follows:

#          Match the forwarding address of the route (8082 is the threat-ip microservice port)
          uri: http://localhost:8082

As a result, you can visit it


of course, the rewritepath path rewriting error in filters may also cause access error. Other reasons will be added later.


Read More: