加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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运行时得到了:

Error while loading /tmp/app.psgi: Paths need to start with / at
/home/cw/.anyenv/envs/plenv/versions/5.20.3/lib/perl5/site_perl/5.20.3/Plack/Builder.pm
line 108.

怎么了?

解决方法

我没有在文档中明确提到这一点,但除主机名外还必须包含路径组件,例如: 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;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读