You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.js 916B

12345678910111213141516171819202122232425262728293031
  1. import { loadScript } from '../../base/util';
  2. /**
  3. * Loads config.js file from remote server.
  4. *
  5. * @param {string} host - Host where config.js is hosted.
  6. * @param {string} configLocation='/config.js' - Relative pah to config.js file.
  7. * @returns {Promise<Object>}
  8. */
  9. export function loadConfig(host, configLocation = '/config.js') {
  10. return loadScript(new URL(configLocation, host).toString())
  11. .then(() => {
  12. const config = window.config;
  13. // We don't want to pollute global scope.
  14. window.config = undefined;
  15. if (typeof config !== 'object') {
  16. throw new Error('window.config is not an object');
  17. }
  18. return config;
  19. })
  20. .catch(error => {
  21. console.error(
  22. `Failed to load ${configLocation} from ${host}`,
  23. error);
  24. throw error;
  25. });
  26. }