aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Tilma.pm46
-rw-r--r--t/app/controller/tilma.t12
2 files changed, 58 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Tilma.pm b/perllib/FixMyStreet/App/Controller/Tilma.pm
new file mode 100644
index 000000000..1be481949
--- /dev/null
+++ b/perllib/FixMyStreet/App/Controller/Tilma.pm
@@ -0,0 +1,46 @@
+package FixMyStreet::App::Controller::Tilma;
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'Catalyst::Controller'; }
+
+use LWP::UserAgent;
+
+=head1 NAME
+
+FixMyStreet::App::Controller::Tilma - Tilma proxy
+
+=head1 DESCRIPTION
+
+A tilma proxy - only intended to be used during dev. In production the webserver should do this proxying.
+
+=head1 METHODS
+
+=head2 default
+
+Proxy everything through to the tilma servers.
+
+=cut
+
+sub default : Path {
+ my ( $self, $c ) = @_;
+
+ my $path = $c->req->uri->path_query;
+ $path =~ s{/tilma/}{};
+
+ my $tilma_uri = URI->new("http://tilma.mysociety.org/$path");
+
+ my $tilma_res = LWP::UserAgent->new->get($tilma_uri);
+
+ if ( $tilma_res->is_success ) {
+ $c->res->content_type( $tilma_res->content_type );
+ $c->res->body( $tilma_res->content );
+ }
+ else {
+ die sprintf "Error getting %s: %s", $tilma_uri, $tilma_res->message;
+ }
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
diff --git a/t/app/controller/tilma.t b/t/app/controller/tilma.t
new file mode 100644
index 000000000..0eb0b251e
--- /dev/null
+++ b/t/app/controller/tilma.t
@@ -0,0 +1,12 @@
+use strict;
+use warnings;
+
+use Test::More;
+use FixMyStreet::TestMech;
+
+my $mech = FixMyStreet::TestMech->new;
+
+$mech->get_ok('/tilma/tileserver/10k-full/3278-3283,1110-1115/JSON');
+is $mech->res->content_type, 'text/javascript', "got JS response";
+
+done_testing(); \ No newline at end of file