Skip to content
This repository has been archived by the owner on Apr 4, 2018. It is now read-only.

Commit

Permalink
Get around jsonp issues by proxying those calls
Browse files Browse the repository at this point in the history
  • Loading branch information
jystewart committed Feb 3, 2012
1 parent 9bc73ce commit e36b08d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 8 additions & 1 deletion config.ru
Expand Up @@ -3,12 +3,19 @@ use Rack::Static,
:root => "public"

run lambda { |env|
request = Rack::Request.new(env)
if request.path.match(/^\/api\/(.*)/)
body = open("https://www.gov.uk/#{$1}")
else
body = File.open('public/index.html', File::RDONLY)
end

[
200,
{
'Content-Type' => 'text/html',
'Cache-Control' => 'public, max-age=86400'
},
File.open('public/index.html', File::RDONLY)
body
]
}
8 changes: 4 additions & 4 deletions public/index.html
Expand Up @@ -100,7 +100,7 @@ <h2>Result</h2>
<script type="text/javascript" charset="utf-8">
var GdsExplorer = {
load_topics: function () {
var topic_list = $.getJSON('https://www.gov.uk/browse.json', function (data) {
var topic_list = $.getJSON('/api/browse.json', function (data) {
var options = '';
for (i = 0; i <= data.length; i++) {
options.push('<option value="' + data[i] + '">' + data[i] + '</option>');
Expand All @@ -111,9 +111,9 @@ <h2>Result</h2>

handle_search: function () {
if (jQuery('#search').val() != '') {
var url = "https://www.gov.uk/search.json?q=" + jQuery('#search').val();
jQuery("#url").text("URL: " + url);
$.getJSON(url + '&callback=?', function (data) {
var path = "/search.json?q=" + jQuery('#search').val();
jQuery("#url").text("URL: https://www.gov.uk" + path);
$.getJSON('/api' + path, function (data) {
console.log(data);
});
} else {
Expand Down

0 comments on commit e36b08d

Please sign in to comment.