DefaultProxy.js 687 B

1234567891011121314151617181920212223242526
  1. /**
  2. * A simple proxy that appends the desired resource as the sole query parameter
  3. * to the given proxy URL.
  4. *
  5. * @alias DefaultProxy
  6. * @constructor
  7. * @extends {Proxy}
  8. *
  9. * @param {String} proxy The proxy URL that will be used to requests all resources.
  10. */
  11. function DefaultProxy(proxy) {
  12. this.proxy = proxy;
  13. }
  14. /**
  15. * Get the final URL to use to request a given resource.
  16. *
  17. * @param {String} resource The resource to request.
  18. * @returns {String} proxied resource
  19. */
  20. DefaultProxy.prototype.getURL = function (resource) {
  21. const prefix = this.proxy.indexOf("?") === -1 ? "?" : "";
  22. return this.proxy + prefix + encodeURIComponent(resource);
  23. };
  24. export default DefaultProxy;