markokocic opened a new issue, #10238: URL: https://github.com/apache/apisix/issues/10238
### Description It is a very common scenario to have an upstream service and a route that doesn't have the same base uri. In that case, it is necessary to add `proxy_rewrite` plugin and it's `regex_uri` parameter to adapt the request to the backend endpoint. For example, we typically have a route defined under prefix `/some_url/smt/v2` that needs to be proxied to an upstream with prefix `/backend/api/v4/impl`. That can of course be done using `proxy_rewrite` plugin, as described [here](https://apisix.apache.org/docs/apisix/FAQ/#how-do-i-strip-a-prefix-from-a-path-before-forwarding-to-upstream-in-apache-apisix) but the use case is so typical that it would be better to have it built in into upstream or service object, instead of enabling `proxy_rewrite` everywhere. For example, we can add `base_uri` parameter to `upstream` or `service` object and define our route like this: ``` curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' { "uri": "/foo/*", "upstream": { "base_uri": "/bar/baz/", "type": "roundrobin", "nodes": { "httpbin.org:80": 1 } } }' ``` This would proxy all requests coming to /foo/something to /bar/baz/something. It would be equivalent to the following configuration: ``` curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' { "uri": "/foo/*", "plugins": { "proxy-rewrite": { "regex_uri": ["^/foo/(.*)","/bar/baz/$1"] } }, "upstream": { "type": "roundrobin", "nodes": { "httpbin.org:80": 1 } } }' ``` Another benefit of `base_uri` parameter in `upstream` would be that we could reuse an upream object withot a need to specify multiple regex_uri rules in different routes. For example, we can define an upstream like this: ``` { "base_uri": "/bar/baz/", "type": "roundrobin", "nodes": { "httpbin.org:80": 1 } ``` Then we can bind it to different routes (or services) without a need to define proxy_rewrite. ``` { "uri": "/foo/*", "upstream_id": 1 } ``` ``` { "uri": "/fuuu/*", "upstream_id": 1 } ``` Right now, if we would like to achieve the same, we would need to add `proxy_rewrite` plugin with different config to all route definitions. This would make typical endpoint configuration much simpler. The details still need to be worked out. For example if both `base_uri` and `reger_uri` are present, `regex_uri` should have a precedence. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
