blob: af7bba751ec25d7fc119a5a68223f855ab072c2d (
plain) (
blame)
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
|
#!/usr/bin/env perl
use strict;
use warnings;
use lib 'lib';
use Plack::App::Directory;
use Plack::Builder;
use Plack::Request;
use Plack::Response;
use Plack::Runner;
use Tozt;
my $site = Tozt->new_with_options;
$site->render_all;
$site->update_static;
my $site_root = 'site';
my $dir_app = Plack::App::Directory->new(root => $site_root)->to_app;
my $app = sub {
my ($env) = @_;
my $req = Plack::Request->new($env);
if (-d ("$site_root" . $req->path)) {
my $resp = Plack::Response->new(302);
my $path = $req->path;
$path .= '/' unless $path =~ m:/$:;
$resp->location("${path}index.html");
return $resp->finalize;
}
else {
return $dir_app->($env);
}
};
my $runner = Plack::Runner->new;
$runner->parse_options(@ARGV);
$runner->run($app);
|