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.native.js 829B

1234567891011121314151617181920212223242526272829
  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. return loadScript(new URL(path, 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(err => {
  21. console.error(`Failed to load ${path} from ${host}`, err);
  22. throw err;
  23. });
  24. }