diff options
author | Eric Wong <e@80x24.org> | 2022-10-05 22:29:41 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2022-10-07 07:42:43 +0000 |
commit | 5b39ed2b6b3d5d8c24240f1b1df8bfd751b0e6bc (patch) | |
tree | d1da405b84a617a5df3f0e98233f173b6a9e4373 /lib/PublicInbox/WWW.pm | |
parent | 26037c85f73de67197af1987e4c0fa4786ac1e31 (diff) | |
download | public-inbox-5b39ed2b6b3d5d8c24240f1b1df8bfd751b0e6bc.tar.gz |
For backwards-compatibility, this defaults to `first'. When set to `fallback', PublicInbox::WwwCoderepo is favored and cgit is only used as a fallback. Eventually, `rewrite' will also be supported to rewrite cgit URLs to WwwCoderepo ones. Of course, WwwCoderepo is still missing search and other key features, but that's being worked on...
Diffstat (limited to 'lib/PublicInbox/WWW.pm')
-rw-r--r-- | lib/PublicInbox/WWW.pm | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm index 470510ae..f861b192 100644 --- a/lib/PublicInbox/WWW.pm +++ b/lib/PublicInbox/WWW.pm @@ -194,12 +194,19 @@ sub r404 { sub news_cgit_fallback ($) { my ($ctx) = @_; - my $www = $ctx->{www}; - my $env = $ctx->{env}; - my $res = $www->news_www->call($env); - $res = $www->cgit->call($env, $ctx) if $res->[0] == 404; + my $res = $ctx->{www}->news_www->call($ctx->{env}); + + $res->[0] == 404 and ($ctx->{www}->{cgit_fallback} //= do { + my $c = $ctx->{www}->{pi_cfg}->{'publicinbox.cgit'} // 'first'; + $c ne 'first' # `fallback' and `rewrite' => true + } // 0) and $res = $ctx->{www}->coderepo->srv($ctx); + ref($res) eq 'ARRAY' && $res->[0] == 404 and - $res = $www->coderepo->srv($ctx); + $res = $ctx->{www}->cgit->call($ctx->{env}, $ctx); + + ref($res) eq 'ARRAY' && $res->[0] == 404 && + !$ctx->{www}->{cgit_fallback} and + $res = $ctx->{www}->coderepo->srv($ctx); $res; } @@ -484,17 +491,14 @@ sub news_www { sub cgit { my ($self) = @_; - $self->{cgit} //= do { - my $pi_cfg = $self->{pi_cfg}; - - if (defined($pi_cfg->{'publicinbox.cgitrc'})) { + $self->{cgit} //= + (defined($self->{pi_cfg}->{'publicinbox.cgitrc'}) ? do { require PublicInbox::Cgit; - PublicInbox::Cgit->new($pi_cfg); - } else { + PublicInbox::Cgit->new($self->{pi_cfg}); + } : undef) // do { require Plack::Util; Plack::Util::inline_object(call => sub { r404() }); - } - } + }; } sub coderepo { |