perl – 在Plack :: Builder中安装“hosts”
发布时间:2020-12-16 06:21:03 所属栏目:大数据 来源:网络整理
导读:Plack::Builder和 this answer的概要说: # in .psgiuse Plack::Builder;my $app = sub { ... };builder { mount "/foo" = builder { enable "Foo"; $app; }; mount "/bar" = $app2; mount "http://example.com/" = builder { $app3 };}; 我尝试了以下方法:
Plack::Builder和
this answer的概要说:
# 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,[ "Hello 2"] ]; }; my $app3 = sub { return [200,[ "Hello 3"] ]; }; builder { mount "/a1" => builder { $app1 }; mount "http://myhost.com" => builder{ $app2 }; mount "/" => builder{ $app3 }; } 但是当试图用plackup运行时得到了:
怎么了? 解决方法
我没有在文档中明确提到这一点,但除主机名外还必须包含路径组件,例如: 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; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |