У меня проблема, когда пользовательский интерфейс Angular 7 не обслуживается, когда маршрут вызывается через шлюз.
Gateway service (gateway): http://localhost:8060 ---> Routes are located
UI Service (appui) : http://localhost:8091/ ----> This works
Routed URL: http://localhost:8060/appui ----> This does NOT work
Облако версий: Greenwich.SR1, boot: 2.1.5.RELEASE, angular:7
Маршруты автоматически расположены в шлюзе.
[{"route_id":"app_ui","route_object":{"predicate":"org.springframework.cloud.gateway.support.ServerWebExchangeUtils$$Lambda$388/0x0000000800442840@4b6ae744","filters":["OrderedGatewayFilter{delegate=org.springframework.cloud.gateway.filter.factory.StripPrefixGatewayFilterFactory$$Lambda$391/0x0000000800441840@50ab56e2,
order=0}","OrderedGatewayFilter{delegate=org.springframework.cloud.gateway.filter.factory.RewritePathGatewayFilterFactory$$Lambda$393/0x0000000800441040@7b5b5bfe,
order=0}"]},"order":0},{"route_id":"CompositeDiscoveryClient_APPUI","route_definition":{"id":"CompositeDiscoveryClient_APPUI","predicates":[{"name":"Path","args":{"pattern":"/appui/**"}}],"filters":[{"name":"RewritePath","args":{"regexp":"/appui/(?<remaining>.*)","replacement":"/${remaining}"}}],"uri":"lb://APPUI","order":0},"order":0},{"route_id":"CompositeDiscoveryClient_GATEWAY","route_definition":{"id":"CompositeDiscoveryClient_GATEWAY","predicates":[{"name":"Path","args":{"pattern":"/gateway/**"}}],"filters":[{"name":"RewritePath","args":{"regexp":"/gateway/(?<remaining>.*)","replacement":"/${remaining}"}}],"uri":"lb://GATEWAY","order":0},"order":0}]
В шлюзе я определил построитель маршрутов, чтобы добавить трейлинг / на маршрут пользовательского интерфейса.**** Примечание: это только последняя версия, я пробовал множество комбинаций. **
@Bean
RouteLocator routes(final RouteLocatorBuilder routeBuilder) {
return routeBuilder.routes()
.route("app_ui",
route -> {
Route.AsyncBuilder uri = route
.path("/appui/**")
.filters(
f -> f.stripPrefix(1).rewritePath("/appui/(?<RID>.*)", "/${RID}/")
)
.uri("http://localhost:8091");
System.out.println(uri);
return uri;
}
)
.build();
}
Журналы шлюза ниже показывают, что маршрут использует службу пользовательского интерфейса, но возвращает сами файлы, ноне отображаемое содержимое:
2019-06-06 13:15:37.823 DEBUG 18900 --- [ctor-http-nio-2] o.s.w.s.adapter.HttpWebHandlerAdapter : [7e7b22d4] HTTP GET "/appui"
2019-06-06 13:15:38.125 DEBUG 18900 --- [ctor-http-nio-2] o.s.w.s.adapter.HttpWebHandlerAdapter : [7e7b22d4] Completed 304 NOT_MODIFIED
2019-06-06 13:15:38.139 DEBUG 18900 --- [ctor-http-nio-2] o.s.w.s.adapter.HttpWebHandlerAdapter : [7e7b22d4] HTTP GET "/styles.3d37d63d23d319945b7f.css"
2019-06-06 13:15:38.142 DEBUG 18900 --- [ctor-http-nio-2] o.s.w.r.handler.SimpleUrlHandlerMapping : [7e7b22d4] Mapped to ResourceWebHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/"]
2019-06-06 13:15:38.149 DEBUG 18900 --- [ctor-http-nio-2] o.s.w.r.resource.ResourceWebHandler : [7e7b22d4] Resource not found
2019-06-06 13:15:38.153 DEBUG 18900 --- [ctor-http-nio-3] o.s.w.s.adapter.HttpWebHandlerAdapter : [564a0604] HTTP GET "/runtime.26209474bfa8dc87a77c.js"
2019-06-06 13:15:38.155 DEBUG 18900 --- [ctor-http-nio-3] o.s.w.r.handler.SimpleUrlHandlerMapping : [564a0604] Mapped to ResourceWebHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/"]
2019-06-06 13:15:38.158 DEBUG 18900 --- [ctor-http-nio-3] o.s.w.r.resource.ResourceWebHandler : [564a0604] Resource not found
2019-06-06 13:15:38.158 DEBUG 18900 --- [ctor-http-nio-8] o.s.w.s.adapter.HttpWebHandlerAdapter : [69d992f7] HTTP GET "/polyfills.8bbb231b43165d65d357.js"
2019-06-06 13:15:38.159 DEBUG 18900 --- [ctor-http-nio-1] o.s.w.s.adapter.HttpWebHandlerAdapter : [3733013b] HTTP GET "/main.d366f2c101e009ba6c55.js"
2019-06-06 13:15:38.161 DEBUG 18900 --- [ctor-http-nio-8] o.s.w.r.handler.SimpleUrlHandlerMapping : [69d992f7] Mapped to ResourceWebHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/"]
2019-06-06 13:15:38.162 DEBUG 18900 --- [ctor-http-nio-1] o.s.w.r.handler.SimpleUrlHandlerMapping : [3733013b] Mapped to ResourceWebHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/"]
2019-06-06 13:15:38.165 DEBUG 18900 --- [ctor-http-nio-8] o.s.w.r.resource.ResourceWebHandler : [69d992f7] Resource not found
2019-06-06 13:15:38.166 DEBUG 18900 --- [ctor-http-nio-1] o.s.w.r.resource.ResourceWebHandler : [3733013b] Resource not found
2019-06-06 13:15:38.186 DEBUG 18900 --- [ctor-http-nio-8] a.w.r.e.AbstractErrorWebExceptionHandler : [69d992f7] Resolved [ResponseStatusException: 404 NOT_FOUND] for HTTP GET /polyfills.8bbb231b43165d65d357.js
2019-06-06 13:15:38.186 DEBUG 18900 --- [ctor-http-nio-3] a.w.r.e.AbstractErrorWebExceptionHandler : [564a0604] Resolved [ResponseStatusException: 404 NOT_FOUND] for HTTP GET /runtime.26209474bfa8dc87a77c.js
2019-06-06 13:15:38.186 DEBUG 18900 --- [ctor-http-nio-1] a.w.r.e.AbstractErrorWebExceptionHandler : [3733013b] Resolved [ResponseStatusException: 404 NOT_FOUND] for HTTP GET /main.d366f2c101e009ba6c55.js
Вот журналы службы UI:
2019-06-06 13:15:38.061 DEBUG 11120 --- [io-8091-exec-10] o.s.web.servlet.DispatcherServlet : GET "/", parameters={}
2019-06-06 13:15:38.063 DEBUG 11120 --- [io-8091-exec-10] o.s.b.a.w.s.WelcomePageHandlerMapping : Mapped to ParameterizableViewController [view="forward:index.html"]
2019-06-06 13:15:38.063 DEBUG 11120 --- [io-8091-exec-10] o.s.w.s.v.ContentNegotiatingViewResolver : Selected 'text/html' given [text/html, application/xhtml+xml, image/webp, image/apng, application/signed-exchange;v=b3, application/xml;q=0.9, */*;q=0.8]
2019-06-06 13:15:38.063 DEBUG 11120 --- [io-8091-exec-10] o.s.w.servlet.view.InternalResourceView : View name 'forward:', model {}
2019-06-06 13:15:38.063 DEBUG 11120 --- [io-8091-exec-10] o.s.w.servlet.view.InternalResourceView : Forwarding to [index.html]
2019-06-06 13:15:38.064 DEBUG 11120 --- [io-8091-exec-10] o.s.web.servlet.DispatcherServlet : "FORWARD" dispatch for GET "/index.html", parameters={}
2019-06-06 13:15:38.065 DEBUG 11120 --- [io-8091-exec-10] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped to ResourceHttpRequestHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/", "/"]
2019-06-06 13:15:38.089 DEBUG 11120 --- [io-8091-exec-10] o.s.web.servlet.DispatcherServlet : Exiting from "FORWARD" dispatch, status 304
2019-06-06 13:15:38.089 DEBUG 11120 --- [io-8091-exec-10] o.s.web.servlet.DispatcherServlet : Completed 304 NOT_MODIFIED
My Gateway application.yml выглядит следующим образом:
server:
port: 8060
spring:
application:
name: gateway
cloud:
gateway:
discovery:
locator:
enabled: true
lowerCaseServiceId: true
eureka:
client:
fetch-registry: true
register-with-eureka: true
serviceUrl:
defaultZone: http://localhost:8082/eureka
healthcheck:
enabled: true
management:
endpoint:
gateway:
enabled: true
endpoints:
web:
exposure:
include: gateway
Мой пользовательский интерфейс application.yml:
server:
port: 8091
spring:
application:
name: appui
management:
health:
binders:
enabled: true
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8082/eureka
healthcheck:
enabled: true
Может ли маршрут с балансировкой нагрузки повлиять на переписывание или добавление завершающего / для пользовательского интерфейса или это что-то еще?
Спасибо!
Пробовал переписывать маршруты, добавляя трейлинг /