Created
September 27, 2014 15:39
-
-
Save thgreasi/83e88ace7c7c67bfda31 to your computer and use it in GitHub Desktop.
crossGetProviders
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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