zowe / zowe/api-layer

Default route path replacement is different in v3 and v2

Open
#3,652 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement help-wanted Priority: High size/M
Dominant language
Java
Stars
92
Forks
81
Avg merge
1d 9h
Merged PRs (30d)
46

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Spring Cloud Gateway's RewritePathGatewayFilterFactory and the logged ui-v1 route definition, comparing the v3 behavior with the described v2 behavior. Trace how requests with and without trailing slashes are rewritten, then determine whether the selected redirect or replacement approach preserves the UI base URL and its static-asset requests.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.