Can I render template data conditionally to my service group matching a string?


#1

In other words, can I do something like:

  {{#if pkg.svc.group.<groupname> ~}}
  <some config for <groupname>>
  {{/if ~}}

?


#2

Unfortunately the #if operator only works on truthy things (e.g. booleans, presence-or-absence, etc.), and doesn’t handle arbitrary boolean expressions.

What’s the usecase you’re trying to serve?


#3

We’re building and shipping an Angular app that has some hard-coded internal URLs depending on whether it’s been built for a validation env or a production one. So we’d like to be able to dynamically point Nginx as the right set of assets depending on which service group we are running as.


#4

Could those URLs be externalized in Habitat config? Then you could add the appropriate URLs to the service group as a whole, and your application doesn’t need to have such intimate knowledge of where it’s running.


#5

Not easily - this stuff gets webpack-ed into minified JS and then served.

What we might end up doing is having 2 location directives in our Nginx config pointing to the two sets of assets, with appropriate rewrite rules.


#6

That sounds like a good approach.


#7

What you could also do is try to export the config in its own json file.

Say a file at /config.json that would be assembled by habitat, and the app requires this file whatever the environment, it’ll always be in the same place. I’ve done it in the past, worked pretty well, and it’s quite cheap to implement ^^


#8

Reasonable. We might also ask the JS devs to make the app modular (might turn out to be easier).