summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2024-04-24 19:54:24 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2024-04-24 19:54:24 +0200
commitf51b692a69bb6efdba4017e30b16e2a29d783bfc (patch)
tree30cb80bb3dc61f6cd5977ed7204d96fc0ea3c758
parenta85266ef8432271d988f00e83da9f5ed350f7097 (diff)
stationboard: handle accept: application/json as well
-rw-r--r--lib/DBInfoscreen.pm3
-rw-r--r--lib/DBInfoscreen/Controller/Stationboard.pm7
2 files changed, 8 insertions, 2 deletions
diff --git a/lib/DBInfoscreen.pm b/lib/DBInfoscreen.pm
index 49e7402..c784e96 100644
--- a/lib/DBInfoscreen.pm
+++ b/lib/DBInfoscreen.pm
@@ -289,7 +289,8 @@ sub startup {
$r->get('/')->to('stationboard#handle_request');
$r->get('/multi/*station')->to('stationboard#handle_request');
- $r->get('/*station')->to('stationboard#handle_request');
+ $r->get( '/*station' => [ format => [ 'html', 'json' ] ] )
+ ->to( 'stationboard#handle_request', format => undef );
$self->types->type( json => 'application/json; charset=utf-8' );
diff --git a/lib/DBInfoscreen/Controller/Stationboard.pm b/lib/DBInfoscreen/Controller/Stationboard.pm
index 078be87..6893cc0 100644
--- a/lib/DBInfoscreen/Controller/Stationboard.pm
+++ b/lib/DBInfoscreen/Controller/Stationboard.pm
@@ -469,7 +469,12 @@ sub handle_request {
# (or used by) marudor.de, it was renamed to 'json'. Many clients won't
# notice this for year to come, so we make sure mode=marudor still works as
# intended.
- if ( $template eq 'marudor' ) {
+ if (
+ $template eq 'marudor'
+ or ( $self->req->headers->accept
+ and $self->req->headers->accept eq 'application/json' )
+ )
+ {
$template = 'json';
}