user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] cgit: improve handling of cgit data path
Date: Thu, 25 Apr 2019 08:02:36 +0000	[thread overview]
Message-ID: <20190425080236.19016-1-e@80x24.org> (raw)

Document `publicinbox.cgitdata' config directive, but allow it
to be unspecified and/or missing for installations which do not
wish to serve static data at all.

For users installing cgit from source to their home directory,
we can usually infer the cgit data path based on the cgit.cgi
binary path, even.
---
 Documentation/public-inbox-config.pod |  9 +++++++++
 lib/PublicInbox/Cgit.pm               | 16 +++++++++++++---
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/Documentation/public-inbox-config.pod b/Documentation/public-inbox-config.pod
index f894eb3..2915022 100644
--- a/Documentation/public-inbox-config.pod
+++ b/Documentation/public-inbox-config.pod
@@ -217,6 +217,15 @@ directive is configured.
 
 Default: /var/www/htdocs/cgit/cgit.cgi or /usr/lib/cgit/cgit.cgi
 
+=item publicinbox.cgitdata
+
+A path to the data directory used by cgit for storing static files.
+Typically guessed based the location of C<cgit.cgi> (from
+C<publicinbox.cgitbin>, but may be overridden.
+
+Default: basename of C<publicinbox.cgitbin>, /var/www/htdocs/cgit/
+or /usr/share/cgit/
+
 =back
 
 =head2 NAMED LIMITER (PSGI)
diff --git a/lib/PublicInbox/Cgit.pm b/lib/PublicInbox/Cgit.pm
index 8922ec5..353f416 100644
--- a/lib/PublicInbox/Cgit.pm
+++ b/lib/PublicInbox/Cgit.pm
@@ -35,7 +35,15 @@ sub locate_cgit ($) {
 		}
 	}
 	unless (defined $cgit_data) {
-		foreach my $d (qw(/var/www/htdocs/cgit /usr/share/cgit)) {
+		my @dirs = qw(/var/www/htdocs/cgit /usr/share/cgit);
+
+		# local installs of cgit from source have
+		# CGIT_SCRIPT_PATH==CGIT_DATA_PATH by default,
+		# so we can usually infer the cgit_data path from cgit_bin
+		if (defined($cgit_bin) && $cgit_bin =~ m!\A(.+?)/[^/]+\z!) {
+			unshift @dirs, $1 if -d $1;
+		}
+		foreach my $d (@dirs) {
 			my $f = "$d/cgit.css";
 			next unless -f $f;
 			$cgit_data = $d;
@@ -90,6 +98,7 @@ my @PASS_ENV = qw(
 sub call {
 	my ($self, $env) = @_;
 	my $path_info = $env->{PATH_INFO};
+	my $cgit_data;
 
 	# handle requests without spawning cgit iff possible:
 	if ($path_info =~ m!\A/(.+?)/($PublicInbox::GitHTTPBackend::ANY)\z!ox) {
@@ -97,10 +106,11 @@ sub call {
 		if (my $git = $self->{"\0$nick"}) {
 			return serve($env, $git, $path);
 		}
-	} elsif ($path_info =~ m!$self->{static}!) {
+	} elsif ($path_info =~ m!$self->{static}! &&
+		 defined($cgit_data = $self->{cgit_data})) {
 		my $f = $1;
 		my $type = Plack::MIME->mime_type($f);
-		return static_result($env, [], "$self->{cgit_data}$f", $type);
+		return static_result($env, [], $cgit_data.$f, $type);
 	}
 
 	my $cgi_env = { PATH_INFO => $path_info };
-- 
EW


                 reply	other threads:[~2019-04-25  8:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190425080236.19016-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).