]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1532766 - Make the the application root a static, cache-friendly redirect to...
authorDylan William Hardison <dylan@hardison.net>
Fri, 8 Mar 2019 22:29:44 +0000 (17:29 -0500)
committerGitHub <noreply@github.com>
Fri, 8 Mar 2019 22:29:44 +0000 (17:29 -0500)
Bugzilla/App.pm
Bugzilla/App/CGI.pm
Bugzilla/App/Home.pm [deleted file]
Bugzilla/App/Main.pm [new file with mode: 0644]
extensions/BzAPI/Extension.pm
t/mojo-example.t
template/en/default/global/header.html.tmpl
template/en/default/main/root.html.tmpl [new file with mode: 0644]

index 68a3199fb2fa3165ad38bb35bab4f2e05a3e1cfe..1f8f597f807bd1013de2c40c7b4e5bf69887ccc0 100644 (file)
@@ -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/<id:num>')->to('CGI#show_bug_cgi');
-  $r->any('/<id:num>')->to('CGI#show_bug_cgi');
-  $r->get('/testagent.cgi')->to('CGI#testagent');
-  $r->add_type('hex32' => qr/[[:xdigit:]]{32}/);
-  $r->post('/announcement/hide/<checksum:hex32>')->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;
index aaedb34851c3ba21a5d0dd52180e87006704f6fc..ebe156a0e90ac110c3b927072a3d9fa46a0932cb 100644 (file)
@@ -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/<id:num>')->to('CGI#show_bug_cgi');
+  $r->any('/<id:num>')->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 (file)
index bd21c45..0000000
+++ /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 (file)
index 0000000..5c06b55
--- /dev/null
@@ -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/<checksum:hex32>')->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;
index e4689596c94db610a30a871ce8908e67c5ef6dad..df80974cf9008ef241a9db5118950d735b879013 100644 (file)
@@ -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;
index 46ab5fbb488b2e35d2573c2a7ecdd813ad47b3b3..005221ad88a930233f34733af00bad04fe8b4e2b 100644 (file)
@@ -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});
index cca9ef6ed57022c3dc81b678c15530d6da7de300..4ac9f7a3ec72a272babd8e7004ec34cf091b186c 100644 (file)
     [% IF Param('utf8') %]
       <meta charset="UTF-8">
     [% END %]
+    [% IF meta_refresh %]
+      <meta http-equiv="refresh"
+        content="[% meta_refresh FILTER html %]">
+    [% END %]
     [% USE Bugzilla %]
 
     [% IF Bugzilla.cgi.should_block_referrer %]
 
 <header id="header" role="banner">
   <div class="inner">
-    <h1 id="header-title" class="title"><a href="[% basepath FILTER none %]" title="Go to home page">[% terms.Bugzilla %]</a></h1>
+    <h1 id="header-title" class="title"><a href="[% c.url_for('/home').to_abs FILTER html %]" title="Go to home page">[% terms.Bugzilla %]</a></h1>
     <form role="search" id="header-search" class="quicksearch" action="[% basepath FILTER none %]buglist.cgi" data-no-csrf>
       <section class="searchbox-outer dropdown" role="combobox" aria-expanded="false" aria-haspopup="listbox"
                aria-owns="header-search-dropdown">
diff --git a/template/en/default/main/root.html.tmpl b/template/en/default/main/root.html.tmpl
new file mode 100644 (file)
index 0000000..4c5f61b
--- /dev/null
@@ -0,0 +1,2 @@
+[% SET home_url = c.url_for('/home').to_abs %]
+[% PROCESS index.html.tmpl meta_refresh="0;URL='$home_url'" %]