From: Dylan William Hardison Date: Fri, 8 Mar 2019 22:29:44 +0000 (-0500) Subject: Bug 1532766 - Make the the application root a static, cache-friendly redirect to... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=60d83a41f87ad3f564b4319b85574a55447da425;p=thirdparty%2Fbugzilla.git Bug 1532766 - Make the the application root a static, cache-friendly redirect to /home --- diff --git a/Bugzilla/App.pm b/Bugzilla/App.pm index 68a3199fb..1f8f597f8 100644 --- a/Bugzilla/App.pm +++ b/Bugzilla/App.pm @@ -24,7 +24,7 @@ use Bugzilla::Logging; use Bugzilla::App::CGI; use Bugzilla::App::OAuth2::Clients; use Bugzilla::App::SES; -use Bugzilla::App::Home; +use Bugzilla::App::Main; use Bugzilla::App::API; use Bugzilla::App::Static; use Mojo::Loader qw( find_modules ); @@ -152,22 +152,10 @@ sub setup_routes { my $r = $self->routes; Bugzilla::App::CGI->setup_routes($r); - Bugzilla::App::CGI->load_one('bzapi_cgi', 'extensions/BzAPI/bin/rest.cgi'); - - $r->get('/home')->to('Home#index'); - $r->any('/')->to('CGI#index_cgi'); - $r->any('/bug/')->to('CGI#show_bug_cgi'); - $r->any('/')->to('CGI#show_bug_cgi'); - $r->get('/testagent.cgi')->to('CGI#testagent'); - $r->add_type('hex32' => qr/[[:xdigit:]]{32}/); - $r->post('/announcement/hide/')->to('CGI#announcement_hide'); - - $r->any('/rest')->to('CGI#rest_cgi'); - $r->any('/rest.cgi/*PATH_INFO')->to('CGI#rest_cgi' => {PATH_INFO => ''}); - $r->any('/rest/*PATH_INFO')->to('CGI#rest_cgi' => {PATH_INFO => ''}); - $r->any('/extensions/BzAPI/bin/rest.cgi/*PATH_INFO')->to('CGI#bzapi_cgi'); - $r->any('/latest/*PATH_INFO')->to('CGI#bzapi_cgi'); - $r->any('/bzapi/*PATH_INFO')->to('CGI#bzapi_cgi'); + Bugzilla::App::Main->setup_routes($r); + Bugzilla::App::API->setup_routes($r); + Bugzilla::App::SES->setup_routes($r); + Bugzilla::App::OAuth2::Clients->setup_routes($r); $r->static_file('/__lbheartbeat__'); $r->static_file( @@ -178,15 +166,6 @@ sub setup_routes { $r->page('/user_profile', 'user_profile.html'); $r->page('/userprofile', 'user_profile.html'); $r->page('/request_defer', 'request_defer.html'); - - $r->get('/__heartbeat__')->to('CGI#heartbeat_cgi'); - $r->get('/robots.txt')->to('CGI#robots_cgi'); - $r->any('/login')->to('CGI#index_cgi' => {'GoAheadAndLogIn' => '1'}); - $r->any('/:new_bug' => [new_bug => qr{new[-_]bug}])->to('CGI#new_bug_cgi'); - - Bugzilla::App::API->setup_routes($r); - Bugzilla::App::SES->setup_routes($r); - Bugzilla::App::OAuth2::Clients->setup_routes($r); } 1; diff --git a/Bugzilla/App/CGI.pm b/Bugzilla/App/CGI.pm index aaedb3485..ebe156a0e 100644 --- a/Bugzilla/App/CGI.pm +++ b/Bugzilla/App/CGI.pm @@ -22,20 +22,6 @@ use Bugzilla::Constants qw(bz_locations USAGE_MODE_BROWSER); our $C; my %SEEN; -sub testagent { - my ($self) = @_; - $self->render(text => "OK Mojolicious"); -} - -sub announcement_hide { - my ($self) = @_; - my $checksum = $self->param('checksum'); - if ($checksum && $checksum =~ /^[[:xdigit:]]{32}$/) { - $self->session->{announcement_checksum} = $checksum; - } - $self->render(json => {}); -} - sub setup_routes { my ($class, $r) = @_; @@ -44,6 +30,19 @@ sub setup_routes { $class->load_one($name, $file); $r->any("/$file")->to("CGI#$name"); } + $r->get('/home')->to('CGI#index_cgi'); + + $r->any('/bug/')->to('CGI#show_bug_cgi'); + $r->any('/')->to('CGI#show_bug_cgi'); + + $r->any('/rest')->to('CGI#rest_cgi'); + $r->any('/rest.cgi/*PATH_INFO')->to('CGI#rest_cgi' => {PATH_INFO => ''}); + $r->any('/rest/*PATH_INFO')->to('CGI#rest_cgi' => {PATH_INFO => ''}); + + $r->get('/__heartbeat__')->to('CGI#heartbeat_cgi'); + $r->get('/robots.txt')->to('CGI#robots_cgi'); + $r->any('/login')->to('CGI#index_cgi' => {'GoAheadAndLogIn' => '1'}); + $r->any('/:new_bug' => [new_bug => qr{new[-_]bug}])->to('CGI#new_bug_cgi'); } sub load_one { diff --git a/Bugzilla/App/Home.pm b/Bugzilla/App/Home.pm deleted file mode 100644 index bd21c45c0..000000000 --- a/Bugzilla/App/Home.pm +++ /dev/null @@ -1,27 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -# This Source Code Form is "Incompatible With Secondary Licenses", as -# defined by the Mozilla Public License, v. 2.0. - -package Bugzilla::App::Home; -use Mojo::Base 'Mojolicious::Controller'; - -use Bugzilla::Error; -use Try::Tiny; -use Bugzilla::Constants; - -sub index { - my ($c) = @_; - $c->bugzilla->login(LOGIN_REQUIRED) or return; - try { - ThrowUserError('invalid_username', {login => 'batman'}) if $c->param('error'); - $c->render(handler => 'bugzilla', template => 'index'); - } - catch { - $c->bugzilla->error_page($_); - }; -} - -1; diff --git a/Bugzilla/App/Main.pm b/Bugzilla/App/Main.pm new file mode 100644 index 000000000..5c06b55f3 --- /dev/null +++ b/Bugzilla/App/Main.pm @@ -0,0 +1,46 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. + +package Bugzilla::App::Main; +use Mojo::Base 'Mojolicious::Controller'; + +use Bugzilla::Error; +use Try::Tiny; +use Bugzilla::Constants; + +sub setup_routes { + my ($class, $r) = @_; + + $r->any('/')->to('Main#root'); + + $r->get('/testagent.cgi')->to('Main#testagent'); + + $r->add_type('hex32' => qr/[[:xdigit:]]{32}/); + $r->post('/announcement/hide/')->to('Main#announcement_hide'); +} + +sub root { + my ($c) = @_; + $c->res->headers->cache_control('public, max-age=3600, immutable'); + $c->render(handler => 'bugzilla'); +} + +sub testagent { + my ($self) = @_; + $self->render(text => "OK Mojolicious"); +} + +sub announcement_hide { + my ($self) = @_; + my $checksum = $self->param('checksum'); + if ($checksum && $checksum =~ /^[[:xdigit:]]{32}$/) { + $self->session->{announcement_checksum} = $checksum; + } + $self->render(json => {}); +} + +1; diff --git a/extensions/BzAPI/Extension.pm b/extensions/BzAPI/Extension.pm index e4689596c..df80974cf 100644 --- a/extensions/BzAPI/Extension.pm +++ b/extensions/BzAPI/Extension.pm @@ -278,7 +278,21 @@ sub _preload_handlers { $cache->{rest_handlers} = $all_handlers; } + + + return $cache->{rest_handlers}; } +sub app_startup { + my ($self, $args) = @_; + my $app = $args->{app}; + my $r = $app->routes; + + Bugzilla::App::CGI->load_one('bzapi_cgi', 'extensions/BzAPI/bin/rest.cgi'); + $r->any('/extensions/BzAPI/bin/rest.cgi/*PATH_INFO')->to('CGI#bzapi_cgi'); + $r->any('/latest/*PATH_INFO')->to('CGI#bzapi_cgi'); + $r->any('/bzapi/*PATH_INFO')->to('CGI#bzapi_cgi'); +} + __PACKAGE__->NAME; diff --git a/t/mojo-example.t b/t/mojo-example.t index 46ab5fbb4..005221ad8 100644 --- a/t/mojo-example.t +++ b/t/mojo-example.t @@ -58,9 +58,11 @@ $t->get_ok('/bzapi/configuration')->status_is(200) ->json_like('/announcement' => qr/Mojo::Test is awesome/); # for web requests, you use text_like (or text_is) with CSS selectors. -$t->get_ok('/')->status_is(200) +$t->get_ok('/home')->status_is(200) ->text_like('#new_announcement div' => qr/Mojo::Test is awesome/); +$t->get_ok('/')->status_is(200); + # Chaining is not magical, you can break up longer lines # by calling methods on $t, as below. $t->get_ok('/rest/whoami' => {'X-Bugzilla-API-Key' => $api_key}); diff --git a/template/en/default/global/header.html.tmpl b/template/en/default/global/header.html.tmpl index cca9ef6ed..4ac9f7a3e 100644 --- a/template/en/default/global/header.html.tmpl +++ b/template/en/default/global/header.html.tmpl @@ -102,6 +102,10 @@ [% IF Param('utf8') %] [% END %] + [% IF meta_refresh %] + + [% END %] [% USE Bugzilla %] [% IF Bugzilla.cgi.should_block_referrer %] @@ -291,7 +295,7 @@