aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Tilma.pm
blob: 1be4819493bb6b0285661b681e49e55e7e9b5b9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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;