forked from DivinumOfficium/divinum-officium
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_env.psgi
More file actions
65 lines (49 loc) · 1.72 KB
/
Copy pathtest_env.psgi
File metadata and controls
65 lines (49 loc) · 1.72 KB
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
use Plack::Builder;
use Plack::App::CGIBin;
use Plack::App::File;
use Cwd qw(abs_path);
use File::Basename qw(dirname);
use FindBin;
=pod
Allows you to run via Plack wrapper
Command: plackup -r -E development test_env.psgi
-r,Reload - Restarts the server automatically when you save files.
-E,Environment - "Sets the context (Development, Deployment, or Test)."
development - Enables verbose error reporting and debugging tools.
test_env.psgi - The specific script that defines your web application
To run on Termux, I had to install the following
$ apt update && apt upgrade -y && pkg install perl -y
$ pkg install perl build-essential
$ cpan App::cpanminus
$ cpanm Plack
$ cpanm CGI::Emulate::PSGI
$ cpanm CGI::Compile
$ plackup -r -E development test_env.psgi
=cut
my $base_dir = $FindBin::Bin;
$ENV{WWWROOT} = "$base_dir/web";
$ENV{PERL5LIB} = join(':', "$base_dir/web/cgi-bin", $ENV{PERL5LIB} || ());
use lib "$FindBin::Bin/web/cgi-bin";
use lib "$FindBin::Bin/web";
builder {
# Helper to fix the directory context for CGI scripts
my $cgi_wrapper = sub {
my $file = shift;
chdir dirname(abs_path($file));
return 1;
};
mount "/cgi-bin/horas" => Plack::App::CGIBin->new(
root => "$base_dir/web/cgi-bin/horas",
exec_cb => $cgi_wrapper
)->to_app;
mount "/cgi-bin/missa" => Plack::App::CGIBin->new(
root => "$base_dir/web/cgi-bin/missa",
exec_cb => $cgi_wrapper # <--- Add this!
)->to_app;
mount "/www" => Plack::App::File->new(
root => "$base_dir/web/www"
)->to_app;
mount "/" => sub {
return [301, ['Location' => '/cgi-bin/horas/officium.pl'], []];
};
};