pajel
February 1, 2019, 4:17pm
1
In addition to the strip_path=true/false option we need to strip only a part (prefix) of the path.
I’d suggest an option like strip_path_prefix="/some-text".
The use case is having a single service with multiple routes attached which allow different consumers, for example:
/route - strip_path=true, allow consumer1
/route/health - strip_path_prefix="/route", allow consumer2
Such rewrites are basic Nginx functionality so it shouldn’t be hard to implement.
I have seen quite a few people asking for this feature, eg:
https://discuss.konghq.com/t/service-with-two-strip-path-routes/2596
https://discuss.konghq.com/t/strip-part-of-a-path-prefix-when-routing/1940
https://discuss.konghq.com/t/strip-some-part-of-uri/735
Appreciate any reaction,
thanks Pavel
17 Likes
gleg
February 1, 2019, 4:30pm
2
This would be really useful for us as well
3 Likes
+1 Agreed would find this helpful also
2 Likes
yes please i am looking for same functionality
Hello guys, i am using kong 1.0.3
i have same micro-service deployed in two countries.
lets say country A and country B. They both will have same endpoints.
i want to achieve the following in KONG.
client calls kong with
/A/api => kong => service-A/api
/B/api => kong => service-B/api
i want to have two services in kong
here the api path is same for different services. service-A and service-B.
They already have a plugin request-transformer-advanced
to handle such case. Although it only available with Enterprise subscription.
But anyway, really looking forward to have such strip_path_prefix
to be available for all. Otherwise we have to create much more services
and routes
for the case…
It would be very useful for us.
jado
August 23, 2019, 7:08am
7
Waiting for that feature as well.
Any update regarding this feature?
This would be very usefull. Our organization is depending on namespacing Service’s for every team, and thus this “team namespace” would be very nice if could be easily removed while preserving the rest of the path.
Meanwhile it seems this community plugin does a good job: https://github.com/alexashley/kong-plugin-path-prefix
Or it should be possible to do it with the request-transformer
Kong plugin , using config.replace.uri
and regex:
config.replace.uri=your-prefix/(\w+):$(uri_captures[1])
1 Like
Since it took me a while to figure things out, I thought sharing my solution might help
For the record, I had the same problem, I end up using:
Full example with Kong Ingress Controller
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: strip-demo-2-path-prefix
config:
path_prefix: "/foo/"
plugin: path-prefix
---
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: set-forwarded-header
plugin: post-function
config:
access:
- |
ngx.var.upstream_x_forwarded_prefix='/foo'
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: demo-2
annotations:
konghq.com/strip-path: "false"
konghq.com/plugins: strip-demo-2-path-prefix,set-forwarded-header
spec:
ingressClassName: kong
rules:
- http:
paths:
- backend:
service:
name: echo
port:
number: 80
path: /foo/bar
pathType: ImplementationSpecific
With this solution:
Requests to /foo/bar
are captured by Kong
They are routed to the upstream service to the path /bar
The forwarded request has the header X-Forwarded-Prefix: /foo
(which makes the upstream service able to find out what its external url is)