dynamic configuration for servers etc.
Hi,
I think about the configuration of the server variables in the configuration. At the moment I have to configure a variable for each service I want to use in my HTML. What about if I have a service registry like Consul or a simple Database etc.? It would be good if there is the possibilty to ask my service registry for the correct URL of the service. The advantage would be if a new service is added or a service is removed you have not to configure it in compoxure. The used variables in the HTML are also independent from the configuration. For the target in the backend configuration it could be similar.
Or do you have a another idea for this issue?
David
Hi David,
If I understand correctly we had the same need a couple of weeks ago. Take a look at the conversation on https://github.com/tes/compoxure/pull/45 and the solution we ended up with on https://github.com/tes/compoxure/pull/46 which gives you the ability to control the final url that gets created for every request.
Hi,
I've played around with this optionsTransformer. Its not what I really needed. In the OptionsTransformer the URL is allready parsed and replaced from the cx-url attribute.
My focus is more on parsing the cx-url attribute.
getCxAttr(fragment, 'cx-url')
If there is defined a variable like {{server:MyService}} I want to ask my service registry for the URL of "MyService". Then the retrieved URL should be used in the initial options. If this would be possible its not neccessary to have a static configuration.
It's a really good question.
The only reason we haven't felt the pain of this is that for us all of our services follow a naming convention managed by the way we configure our platform, e.g.
"app-resource":"app-resource.service.tes-internal.com"
This pretty much never changes for us once configured once, clearly the servers move around but we deal with this via DNS, hence we don't have to dynamically look it up.
You could definitely add an additional call to a passed in function into https://github.com/tes/compoxure/blob/master/src/parameters/RequestInterrogator.js#L16 that did something like you describe.
Could your service registry return an object that is similar to the config? e.g.
"servers": {
"service1":"http://service1.blah",
"service2":"http://service2.blah"
}
Lets see if we can get this PR over the line?