Reputation: 378
I am building a multi-tenant application where the tenant name is contained within every url. For example, a route to retrieve all current users of the tenant "Test" would look like this: /ui/api/Test/users
. The part of the application I am currently working on is a client that forwards the requests of any other application it supports to my DB service, allowing the client to act as a go-between.
You can probably see where this is going. I am using Zuul to forward my routes, but not ALL routes should be forwarded in this manner. Sometimes, the frontend will send requests that start with /ui/api/
that are not database requests. Let's say one of these looks like this: /ui/api/Test/Foo
. I want to able to configure my Zuul routes in such a manner that I can forward any url that fits the pattern /ui/api/*/users
(where * is any string) without forwarding any others.
I have of course attempted to simply use /ui/api/*/users
, but this will not match any route. I haven't tried it, but I assume that it simply interprets * as an actual part of the url. My current workaround is to match /ui/api/**
and then add **/Foo
to the zuul.ignoredPatterns. This works, but is supoptimal, since any new endpoint that I require to not be forwarded will need to be added here. Since the client is meant to be used in various projects, the forwarded routes will not change, but the ones that should not be will. This is not configurable per project and thus not a viable solution.
This is what the relevant part of my application.properties looks like:
zuul.ignoredPatterns = /**/login,/**/executeJobUrl,/**/createExecuteJobUrl
zuul.routes.user-manager.path = /ui/api/**
zuul.routes.user-manager.url = http://localhost:0/eis-user-manager/ui/api
zuul.routes.user-manager.stripPrefix = true
Upvotes: 2
Views: 3073
Reputation: 1568
The working solution is to use **
in the pattern.
So it would be
/ui/api/**/users
I got the idea from here. Credit also to Alex Eggers for testing and suggesting to make an answer.
Upvotes: 3
Reputation: 3372
I have some routes working with partial wildcards, as a solution to a similar problem to what you describe. I could not get a path like /api/**/v1.1/user**
to work, but /api/*admin/v1.1/user**
works fine. I concluded that the wildcard alone was too greedy...
The only but is that you need to name your services something like "somecompanyadmin", "msadmin" and "someothercompanyadmin" instead of "somecompany", "ms" and "someothercompany"...
Here is a sample configuration that works for my case:
zuul:
routes:
mock:
path: /v1.1/**
url: https://myserver:6154/v1.1
users:
path: /api/*admin/v1.1/user**
serviceId: user_server
stripPrefix: true
permission:
path: /api/*admin/v1.1/permission/**
serviceId: permission_server
stripPrefix: true
Upvotes: 2