Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@thgreasi
Created September 27, 2014 15:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thgreasi/83e88ace7c7c67bfda31 to your computer and use it in GitHub Desktop.
Save thgreasi/83e88ace7c7c67bfda31 to your computer and use it in GitHub Desktop.
crossGetProviders
var crossGetProviders = {
whateverorigin: function crossGet(url) {
var promise = $.getJSON('http://whateverorigin.org/get?url=' + encodeURIComponent(url) +
'&callback=?');
var piped = promise.then(function (response) {
return response.contents;
});
return piped;
},
corsproxy: function corsproxy(url) {
url = url.replace("http://", "").replace("https://", "");
var promise = $.get('http://www.corsproxy.com/' + url);
return promise;
},
corsproxyio: function corsproxy(url) {
var promise = $.get('http://cors.corsproxy.io/url=' + url);
return promise;
}
};
function crossGet(url, provider) {
var DEFAULT_PROVIDER = 'corsproxyio';
provider = (provider && provider in crossGetProviders && provider) || DEFAULT_PROVIDER;
var promise = crossGetProviders[provider](url);
return promise;
}
crossGet('http://www.github.com', 'corsproxyio');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment