Open tfabien opened 2 years ago
Another possible way I tried but didn't work
default
as http://store{#context?.attributes['store']}/myLocalApiPath/myApi/
or http://store{#request?.headers['store']}/myLocalApiPath/myApi/
Alas, this configuration leads to an error while deploying the api:
io.gravitee.el.exceptions.ExpressionEvaluationException: The template evaluation returns an error.
at io.gravitee.el.spel.SpelTemplateEngine.getValue(SpelTemplateEngine.java:62)
at io.gravitee.el.spel.SpelTemplateEngine.getValue(SpelTemplateEngine.java:68)
at io.gravitee.el.spel.SpelTemplateEngine.convert(SpelTemplateEngine.java:48)
at io.gravitee.connector.http.HttpConnectorFactory.convert(HttpConnectorFactory.java:81)
at io.gravitee.connector.http.HttpConnectorFactory.resolve(HttpConnectorFactory.java:62)
at io.gravitee.connector.http.HttpConnectorFactory.create(HttpConnectorFactory.java:46)
at io.gravitee.gateway.core.endpoint.lifecycle.impl.EndpointGroupLifecycleManager.start(EndpointGroupLifecycleManager.java:161
:rainbow: Feature
As an Api Designer
I want to dynamically route request to a backend url, using the default endpoint, but replacing host
So that I can dynamicaly route to a specific host following a naming convention without maintaining the whole backend url inside the policy
:sunrise_over_mountains: Additional information
Gravitee dynamic-routing policy states:
The problem I see here, is that you have to explicitely define an endpoint for every "store" and maintain this list This can be a hassle, especially if you have a lot of stores...
If you have an organization where stores backend uris follow a convention (say
https://storeXXX/myLocalApiPath/API-NAME
for any givenXXX
store andAPI-NAME
), you could dynamically route to this store/api without declaring it in the endpointsThe only way you can achieve this at the moment is by defining the whole backend URL (eg: including the
/myLocalApiPath/myApi
part) inside the dynamic routing PolicyBut this solution leads us to maintaining the whole backend uri inside the policy, and not juste the host If I change the endpoint uri afterwards, this change would be ignored by the policy, leading to incomprehension and errors
What I would like to do is defining a
default
endpoint such ashttp://store[PLACEHOLDER]/myLocalApiPath/myApi
:This cannot be done at the moment because
{#endpoints['default']}
only returns thedefault:
placeholder that will be resolved after all policies have executed on to an url by the ProxyEndpointResolverHence the target url generated by the policy would still be
default:restOfUri
, which would still be resolved ashttp://store[PLACEHOLDER]/myLocalApiPath/myApi/restOfUri
later on...Proposition 1:
{#resolve(#endpoints['default']).replace('[PLACEHOLDER]', #group[0])}
)endpointsInfos
variable to the template carrying full endpoint information{#endpointsInfos['default'].target.replace('[PLACEHOLDER]', #group[0])}
ref:
string{#endpoints['default'].target.replace('[PLACEHOLDER]', #group[0])}
The later is a bit cleaner, but it would be a breaking change eg: every
{#endpoint['XXX']}
expression would need to be changed to{#endpoint['XXX'].ref}
whereas the first two solutions are just adding functionalityProposition 2:
Export the resolved endpoint(s) to an
request.resolved.endpoint
attribute, much like therequest.endpoint
attribute that already exist. After the policy execution we would getAnd we could then add a second dynamic routing policy to use this attribute...
Thus
http://store[PLACEHOLDER]/myLocalApiPath/myApi/restOfUri
would becomehttp://storeXXX/myLocalApiPath/myApi/restOfUri
for anyXXX
storeProposition 3
Add a new Policy 'enforce-endpoint-host' letting us change the host when the endpoint is resolved.
:white_check_mark: Acceptance criteria
For all of thoses propositions, If I were to change the endpoint definition of the API (eg: changing it to
http://store[PLACEHOLDER]/my__NEW__LocalApiPath/myApi
), I would still get the correct dynamic endpoint uri without changing anything to the policiesNote: