line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::MountPSGI; |
2
|
7
|
|
|
7
|
|
42406
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
38
|
|
3
|
7
|
|
|
7
|
|
3830
|
use Mojolicious::Plugin::MountPSGI::Proxy; |
|
7
|
|
|
|
|
20
|
|
|
7
|
|
|
|
|
80
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.14'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub register { |
9
|
11
|
|
|
11
|
1
|
67728
|
my ($self, $app, $conf) = @_; |
10
|
|
|
|
|
|
|
|
11
|
11
|
|
|
|
|
29
|
my $rewrite = delete $conf->{rewrite}; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Extract host and path |
14
|
11
|
|
|
|
|
42
|
my $prefix = (keys %$conf)[0]; |
15
|
11
|
|
|
|
|
24
|
my ($host, $path); |
16
|
11
|
50
|
|
|
|
69
|
if ($prefix =~ /^(\*\.)?([^\/]+)(\/.*)?$/) { |
17
|
0
|
|
|
|
|
0
|
$host = quotemeta $2; |
18
|
0
|
0
|
|
|
|
0
|
$host = "(?:.*\\.)?$host" if $1; |
19
|
0
|
|
|
|
|
0
|
$path = $3; |
20
|
0
|
0
|
|
|
|
0
|
$path = '/' unless defined $path; |
21
|
0
|
|
|
|
|
0
|
$host = qr/^$host$/i; |
22
|
|
|
|
|
|
|
} |
23
|
11
|
|
|
|
|
22
|
else { $path = $prefix } |
24
|
|
|
|
|
|
|
|
25
|
11
|
100
|
|
|
|
45
|
my %args = ( |
26
|
|
|
|
|
|
|
rewrite => $rewrite ? $path : undef, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
11
|
50
|
|
|
|
50
|
unless ($ENV{PLACK_ENV}) { |
30
|
11
|
|
|
|
|
86
|
$args{mode} = $app->mode; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
11
|
|
|
|
|
131
|
my $psgi = $conf->{$prefix}; |
34
|
11
|
100
|
|
|
|
30
|
if (ref $psgi) { |
35
|
1
|
|
|
|
|
2
|
$args{app} = $psgi; |
36
|
|
|
|
|
|
|
} else { |
37
|
10
|
50
|
|
|
|
284
|
unless (-r $psgi) { |
38
|
0
|
|
|
|
|
0
|
my $abs = $app->home->rel_file($psgi); |
39
|
0
|
0
|
|
|
|
0
|
$psgi = $abs if -r $abs; |
40
|
|
|
|
|
|
|
} |
41
|
10
|
|
|
|
|
38
|
$args{script} = $psgi; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
11
|
|
|
|
|
97
|
my $proxy = Mojolicious::Plugin::MountPSGI::Proxy->new(%args); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Generate route |
47
|
11
|
|
|
|
|
61177
|
my $route = $app->routes->route($path)->detour(app => $proxy); |
48
|
11
|
50
|
|
|
|
3125
|
$route->over(host => $host) if $host; |
49
|
|
|
|
|
|
|
|
50
|
11
|
|
|
|
|
57
|
return $route; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |
55
|
|
|
|
|
|
|
__END__ |