Get Target Server detail with Hosted Target

jbradley
Participant I

I am creating a NodeJS Hosted Target that will handle message transformation and communication with an internal server. This internal server is already configured as a Target Server, and other services use this Target Server, so I can't yet remove the Target Server, and I'd like to avoid duplicating the Target Server details in a KVM, just for the Hosted Target.

Is it possible to either populate the app.yaml file from the detail of a Hosted Target, or otherwise problematically set environment variables for the Hosted Target based on it's values?

0 4 315
4 REPLIES 4

Hey Joseph,

I'm not sure what you mean by "Is it possible to either populate the app.yaml file from the detail of a Hosted Target". Could you elaborate a bit more on what you want to know about formatting the app.yaml? You are able to configure any environment variable (kvm or not) in your app.yaml through the "env" field if that's what you want to know? For instance:

runtime: node
env:
  - name: DB_ENV
    value: production

As far as dynamically configuring environment variables goes, they are configured in the Hosted Target at deploy time, so it is not possible to dynamically update a Hosted Target's environment variables. If you would like to pass in information dynamically, we recommend passing this information to your Hosted Target through request headers set in the PreFlow section of your proxy.

I mis-typed that part of the question, actually. I should have asked:

> Is it possible to either populate the app.yaml file with the detail of available Target Servers, or otherwise problematically set environment variables for the Hosted Target based on available Target Servers?

What I’m trying to do is create a NodeJS Hosted Target that communicates with servers which are already setup as Target Servers. These Target servers have different hosts for each environment, and are being used by other proxies. I could populate a KVM with the same detail, but if I could somehow avoid duplicating that detail in a KVM, that would be great.

Based on your response, and my research, I think that my options are:

  • Manually populate this info in a env config file or in KVMs for each environment
    • I will have to maintain this info in two places with this option. The Node app will eventually talk to more than one Target Server, based on the user’s configuration, so I’d rather maintain it in only one location.
  • Use the Management API to query this info when the app starts up, and cache it until it needs to be refreshed
    • I think this is the best option. It does use the Management API in the Hosted Target, but only at startup. Plus we don’t have to maintain the info in more than one place.
  • Somehow get info on Target Servers in the proxy flow, before the request is handed off to the app
    • I don’t think this is actually possible, without putting Management API calls in the request flow. I could cache the info, but it would still be making calls in line with the request. I am already populating headers with user config info, and since we may be using JWT auth Keys in the future, I want to keep my current header size as small as possible.

Let me know if you think I’m missing something obvious!

Ah gotcha, that makes more sense. Unfortunately we don't have any constructs in the app.yaml to specify target servers and there is no tooling around dynamically changing an app.yaml at deploy time or otherwise. I think your best bet would be the second point you have there, which would basically reach out to the MGMT server and cache the target servers at the startup of your node code.

Thought so - thanks!