Monday 5 June 2017

Dynamically set JavaScript host in angular2 app

I have an angular2 app that needs to reference some external JavaScript files in index.html.

However, the host for these files will change depending on the environment.

e.g. in production I need:

<script src="http://my-prod-server/libs/my-lib.js"></script>

and then in test I need:

<script src="http://my-test-server/libs/my-lib.js"></script>

Is it possible to change this URL dynamically when the pages are served? So perhaps the index.html would have:

<script src="http://${my-server}/libs/my-lib.js"></script>

and some sort of variable substitution would replace ${my-server} appropriately.

Or are there other options to achieve this?

Thanks



via jtsnr

No comments:

Post a Comment