DefaultProxy.js 758 B

12345678910111213141516171819202122232425
  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. *
  8. * @param {String} proxy The proxy URL that will be used to requests all resources.
  9. */
  10. function DefaultProxy(proxy) {
  11. this.proxy = proxy;
  12. }
  13. /**
  14. * Get the final URL to use to request a given resource.
  15. *
  16. * @param {String} resource The resource to request.
  17. * @returns {String} proxied resource
  18. */
  19. DefaultProxy.prototype.getURL = function(resource) {
  20. var prefix = this.proxy.indexOf('?') === -1 ? '?' : '';
  21. return this.proxy + prefix + encodeURIComponent(resource);
  22. };
  23. export default DefaultProxy;