-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.psgi
70 lines (59 loc) · 2.07 KB
/
app.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
BEGIN {
# Setup app lib paths
require lib;
require File::Spec;
my $base = (File::Spec->splitpath(
File::Spec->rel2abs( readlink(__FILE__) || __FILE__ )))[1];
$base =~ s/\/$//;
lib->import( "$base/lib", );
# Setup Catalyst; it really wants the chdir()
chdir $base
or warn "Couldn't chdir to $base: $!";
$ENV{CATALYST_HOME} = $base;
# Setup %ENV
$ENV{PATH} = '/sbin:/usr/sbin:/bin:/usr/local/bin:/usr/bin';
}
use Plack::Builder;
use Plack::App::File;
use Viroverse::Logger -component => "app.psgi", qw< :log >;
use Viroverse;
my $app = Viroverse->psgi_app;
builder {
# Provide a logger for PSGI components to use
enable sub {
my $app = shift;
return sub {
my $env = shift;
$env->{'psgix.logger'} = Viroverse::Logger->psgi_logger;
return $app->($env);
};
};
enable "NoMultipleSlashes";
# We use resources which vary responses based on the request's Accept:
# header, so caching agents must use Accept: as a cache key. See also the
# Chrome back button behaviour which uncovered our need for Vary:
# https://code.google.com/p/chromium/issues/detail?id=94369
enable 'Header',
append => [ Vary => 'Accept' ];
if (($ENV{PLACK_ENV} || '') eq 'development') {
my $user = $ENV{REMOTE_USER} || $ENV{USER} || `whoami`;
chomp $user;
log_warn { "Forcing REMOTE_USER to '$user'" };
enable "ForceEnv", REMOTE_USER => $user;
if (Viroverse->debug) {
enable "Debug", panels => [];
enable "Debug::DBIC::QueryLog";
enable "Debug::DBITrace", level => "SQL";
enable "Debug::DBIProfile", profile => "!Statement";
enable "Debug::Timer";
enable "Debug::Environment";
enable "Debug::CatalystStash";
enable "Debug::ViroverseLogger";
}
}
mount "/static" => builder {
enable "ConditionalGET";
Plack::App::File->new( root => "$ENV{CATALYST_HOME}/root/static/" );
};
mount "/" => $app;
}