I would be a little different, but in a similar approach to your sed -shellscript.
I like the idea of ββa βtext configuration fileβ that you mentioned, like this:
Serve the configuration file from a known location, for example. ./config ? Since your JS is already loaded from the current site, at least there you should be able to rely on the relative path.
Step 1: running shellscript in the docker container writes configuration parameters from environment variables to the plaintext file and puts it in the same folder as the angular packed code.
Step 2. There is some initialization code in the main HTML file loading the application, for example:
$(function() { $.get('./config') .then(function(res) { window.appConfig = res.data;
Step 3: You use global variables in your angular application, for example. if you use OpaqueToken:
import { OpaqueToken } from '@angular/core'; const CONFIG_TOKEN = new OpaqueToken('config'); export const THIRDPARTYLIBPROVIDERS = [ { provide: CONFIG_TOKEN, useValue: window.appConfig } ];
Yes, this is still a bit hacky, and in your dev-env node-proxy, which you use to serve the ng application, should also expose such a configuration endpoint. In addition, this requires an additional request, but this could be easily avoided by expanding the bit of the init code to cache the data in localStorage, for example (given that this data will not change over time).
But in general, I think this is a little more convenient than sed in some files that you really don't know about how they are laid out.
Let me know what you think!
NoUsername Nov 06 '16 at 20:07 2016-11-06 20:07
source share