endpoint_selector.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * DevExtreme (data/endpoint_selector.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. var errors = require("../core/errors");
  11. var window = require("../core/utils/window").getWindow();
  12. var proxyUrlFormatter = require("./proxy_url_formatter");
  13. var IS_WINJS_ORIGIN;
  14. var IS_LOCAL_ORIGIN;
  15. function isLocalHostName(url) {
  16. return /^(localhost$|127\.)/i.test(url)
  17. }
  18. var EndpointSelector = function(config) {
  19. this.config = config;
  20. IS_WINJS_ORIGIN = "ms-appx:" === window.location.protocol;
  21. IS_LOCAL_ORIGIN = isLocalHostName(window.location.hostname)
  22. };
  23. EndpointSelector.prototype = {
  24. urlFor: function(key) {
  25. var bag = this.config[key];
  26. if (!bag) {
  27. throw errors.Error("E0006")
  28. }
  29. if (proxyUrlFormatter.isProxyUsed()) {
  30. return proxyUrlFormatter.formatProxyUrl(bag.local)
  31. }
  32. if (bag.production) {
  33. if (IS_WINJS_ORIGIN && !Debug.debuggerEnabled || !IS_WINJS_ORIGIN && !IS_LOCAL_ORIGIN) {
  34. return bag.production
  35. }
  36. }
  37. return bag.local
  38. }
  39. };
  40. module.exports = EndpointSelector;
  41. module.exports.default = module.exports;