-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathwebapi-dbic-demo.psgi
50 lines (37 loc) · 1.21 KB
/
webapi-dbic-demo.psgi
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
47
48
49
50
use lib 't/lib';
BEGIN {
$ENV{WM_DEBUG} ||= 0; # verbose
$ENV{DBIC_TRACE} ||= 0;
$ENV{DBI_TRACE} ||= 0;
$ENV{PATH_ROUTER_DEBUG} ||= 0;
$ENV{WEBAPI_DBIC_DEBUG} ||= 0;
$|++;
}
use DummyLoadedSchema;
use Plack::Builder;
use Plack::App::File;
use WebAPI::DBIC::WebApp;
use Alien::Web::HalBrowser;
my $hal_app = Plack::App::File->new(
root => Alien::Web::HalBrowser->dir
)->to_app;
use Devel::Dwarn;
my $schema = DummyLoadedSchema->connect;
my $app = WebAPI::DBIC::WebApp->new({
routes => [ map( $schema->source($_), $schema->sources) ]
})->to_psgi_app;
my $app_prefix = "/clients/v1";
builder {
enable 'SimpleLogger'; # show on STDERR
#enable "Plack::Middleware::AccessLog", format => '%h %l %u %t "%r" %>s %b %{X-Runtime}o';
enable "Runtime", header_name => "X-Runtime";
enable "HTTPExceptions", rethrow => 1;
#enable "StackTrace", force => 1;
#enable sub { my $app=shift; sub { Dwarn my $env=shift; my $res = $app->($env); return $res; }; };
mount "$app_prefix/" => builder {
mount "/browser" => $hal_app;
mount "/" => $app;
};
# root redirect for discovery - redirect to API
mount "/" => sub { [ 302, [ Location => "$app_prefix/" ], [ ] ] };
};