Permalink
Newer
Older
100644 51 lines (38 sloc) 1.27 KB
1
#!/usr/bin/env perl
2
3
use strict;
4
use warnings;
5
use lib qw(lib);
6
7
use Path::Class;
8
use Plack::App::TemplateToolkit;
9
use Plack::Builder;
10
use Plack::Middleware::ErrorDocument;
11
use Plack::Middleware::Static;
12
13
my $root = $ENV{'PLACK_ENV'} eq 'deployment' ? '/home/dotcloud/current/' : './';
14
15
# my $base = dir( file($0)->dir(), 'base' )->stringify();
16
# my $custom = dir( file($0)->dir(), 'custom' )->stringify();
17
my $base = dir( $root, 'base' )->stringify();
18
my $custom = dir( $root, 'custom' )->stringify();
19
20
warn $base;
21
22
# Create our TT app, specifying the root and file extensions
23
my $app = Plack::App::TemplateToolkit->new(
24
root => [ ( $custom, $base ) ], # required
25
# extension => '.html', # optional
26
)->to_app;
27
28
# Plack::Middleware::Deflater might be good to use here
29
30
$app = Plack::Middleware::ErrorDocument->wrap( $app,
31
404 => "$base/page_not_found.html", );
32
33
# Binary files can be served directly
34
$app = Plack::Middleware::Static->wrap(
35
$app,
36
path => qr{[gif|png|jpg|swf|ico|mov|mp3|pdf|js|css]$},
37
root => $base
38
);
39
40
$app = Plack::Middleware::Static->wrap(
41
$app,
42
path => qr{[gif|png|jpg|swf|ico|mov|mp3|pdf|js|css]$},
43
root => $custom,
44
pass_through => 1, # So the 'base' static can pick it up
45
);
46
47
48
return builder {
49
$app;
50
}