Is it possible to configure Zuul routes to match on wildcards?

Alex Eggers :

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
Norbert Bicsi :

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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=128123&siteId=1