Plack::建筑工人和这个答案的概要内容如下:
# in .psgi
use Plack::Builder;
my $app = sub { ... };
builder {
mount "/foo" => builder {
enable "Foo";
$app;
};
mount "/bar" => $app2;
mount "http://example.com/" => builder { $app3 };
};我尝试了以下几点:
use Plack::Builder;
my $app1 = sub { return [200, ['Content-Type' => 'text/plain'], [ "Hello 1"] ]; };
my $app2 = sub { return [200, ['Content-Type' => 'text/plain'], [ "Hello 2"] ]; };
my $app3 = sub { return [200, ['Content-Type' => 'text/plain'], [ "Hello 3"] ]; };
builder {
mount "/a1" => builder { $app1 };
mount "http://myhost.com" => builder{ $app2 };
mount "/" => builder{ $app3 };
}但当试图用plackup运行它时,got:
加载/tmp/app.psgi:路径需要以/ at /home/cw/.anyenv/envs/plenv/versions/5.20.3/lib/perl5/site_perl/5.20.3/Plack/Builder.pm行108开始时出错。
怎么啦?
发布于 2015-10-01 18:42:13
我在文档中没有明确提到这一点,但是除了主机名(例如http://myhost.com/foo )之外,您还必须包括一个路径组件。变化
mount "http://myhost.com" => builder{ $app2 };至
mount "http://myhost.com/" => builder{ $app2 };(即主机/上的myhost.com)
相关代码在Plack::App::URLMap中(mount简单地调用Plack::App::URLMap的map方法):
if ($location =~ m!^https?://(.*?)(/.*)!) {
$host = $1;
$location = $2;
}https://stackoverflow.com/questions/32894204
复制相似问题