]> iEval git - plack-app-gruntmaster.git/commitdiff
Use ?format=json instead of Accept: application/json
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 13 Dec 2014 16:30:39 +0000 (18:30 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 13 Dec 2014 16:30:39 +0000 (18:30 +0200)
js/90-tracker.js
lib/Plack/App/Gruntmaster.pm

index a475ee850bd5ad5fbbd00c5b84c5e30efa6165ec..8e7a4433f8965affad02929e49cc431296d13fa4 100644 (file)
@@ -77,8 +77,7 @@
                $('#tracker_form').addClass('hidden');
                update_tracker();
                var xhr = new XMLHttpRequest();
-               xhr.open('GET', '/us/' + user);
-               xhr.setRequestHeader('Accept', 'application/json');
+               xhr.open('GET', '/us/' + user + '?format=json');
                xhr.onload = function () {
                        localStorage.setItem('tracker_data', this.responseText);
                        update_tracker();
index b84dc81db4b13bcf3ec79a3c65f18912d831233a..af1eb781135205f798ebdbb9b1e9fc98dd1922ed 100644 (file)
@@ -125,11 +125,12 @@ sub dispatch_request{
                        response_filter { return shift }
                },
 
-               sub () {
+               sub (?:format~) {
+                       my $format = lc $_{format} // '';
                        response_filter {
                                my ($r) = @_;
                                return $r if ref $r ne 'Plack::App::Gruntmaster::Response';
-                               return [200, ['Content-Type' => 'application/json', 'X-Forever' => 1], [encode_json $r->{params}]] if $env->{HTTP_ACCEPT} =~ m,^\s*application/json\s*$,g;
+                               return [200, ['Content-Type' => 'application/json', 'X-Forever' => 1], [encode_json $r->{params}]] if $format eq 'json';
                                my $ret = render $r->{template}, 'en', title => $r->{title}, %{$r->{params}};
                                [200, ['Content-Type' => 'text/html'], [encode 'UTF-8', $ret]]
                        },
This page took 0.029871 seconds and 4 git commands to generate.