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 1.1KB

123456789101112131415161718192021222324252627282930313233343536
  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} path='/config.js' - Relative pah to config.js file.
  7. * @returns {Promise<Object>}
  8. */
  9. export function loadConfig(host, path = '/config.js') {
  10. // Returns config.js file from global scope. We can't use the version that's
  11. // being used for the React Native app because the old/current Web app uses
  12. // config from the global scope.
  13. if (typeof APP !== 'undefined') {
  14. return Promise.resolve(window.config);
  15. }
  16. return loadScript(new URL(path, host).toString())
  17. .then(() => {
  18. const config = window.config;
  19. // We don't want to pollute global scope.
  20. window.config = undefined;
  21. if (typeof config !== 'object') {
  22. throw new Error('window.config is not an object');
  23. }
  24. return config;
  25. })
  26. .catch(err => {
  27. console.error(`Failed to load ${path} from ${host}`, err);
  28. throw err;
  29. });
  30. }