Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default route path replacement is different in v3 and v2 #3652

Open
pablocarle opened this issue Jul 17, 2024 · 0 comments
Open

Default route path replacement is different in v3 and v2 #3652

pablocarle opened this issue Jul 17, 2024 · 0 comments
Labels

Comments

@pablocarle
Copy link
Contributor

Is your feature request related to a problem? Please describe.

In API ML v3 with Spring Cloud Gateway, the behaviour when routing with/without trailing slashes changed from the v2 version.

The API Catalog, for example, in direct calls has a 302 redirect from the https://host:catlaog-port/apicatalog to https://host:catalog-port/apicatalog/ which makes the browser stand on the right base URL for followup requests, especially the one bootstrapping the react application.

Frontends such as a the API Catalog need to have the URL with trailing slash when going through the API Gateway (https://:) in v3.

The problem comes from the default implementation in Spring Cloud Gateway's RewritePathGatewayFilterFactory. Which when it removes the route part of the URL (ex. ui/v1) it doesn't respect whether the original client's URL had a trailing slash or not, it always keeps an ending slash.

In a real example, if I request to go to Catalog through gateway via URL https://localhost:<gw_port>/apicatalog/ui/v1 (without trailing slash), gateway will route to https://localhost:<catalog_port>/apicatalog/ which is also correct, but since the browser still thinks it's in https://localhost:<gw_port>/apicatalog/ui/v1, it will try to load https://localhost:<gw_port>/apicatalog/ui/static... which is not covered in the original routes.

Describe the solution you'd like

In my opinion the ideal solution would be to keep the behaviour as in v2, to avoidany breaking change to onboarding services.
This should be implementing either option b or c from the following alternatives.

Describe alternatives you've considered
a. Adding a route for UIs in /ui is a possible workaround

b. Another option which would keep the behaviour as in API ML v2 is to either replace the default RewritePathGatewayFilterFactory with a custom implementation which supports regex patterns for both with and without trailing slash.

c. Spring also recommends having a redirection filter to make sure it's handled properly, as configuration options were deprecated in Spring Framework 6.

Additional context
RewritePathGatewayFilterFactory is the default Filter in Spring Cloud Gateway that handles the path replacement

2024-07-17 11:24:20.804 <ZWEAGW1:DiscoveryClient-CacheRefreshExecutor-0:71860> user DEBUG ((o.s.c.g.r.RouteDefinitionRouteLocator)) RouteDefinition localhost:apicatalog:10014:ui-v1 applying filter {regexp=/apicatalog/ui/
v1/?(?<remaining>.*), replacement=/apicatalog/${remaining}} to RewritePath
@pablocarle pablocarle added enhancement New feature or request new New issue that has not been worked on yet labels Jul 17, 2024
@balhar-jakub balhar-jakub added Priority: High size/M and removed new New issue that has not been worked on yet labels Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

2 participants