Moved npm rewrite rules out of directory scope

mod_rewrite has inconsistent behavior inside of a directory tag. For
example, it doesn't appear to update the value of REQUEST_URI in
subsequent redirects, and the modifiable URI passed to the RewriteRule
is different from that passed to the RewriteCond.

This patch moves the rewrite rules for the npm mirror out of the
directory block, in order to fix unexpected 500 errors when accessing
packages with single file names. It also switches the <directory>
configuration block to only match on subdirectories of /npm/, so that
listing the contents of /npm does not redirect the user to the
/npm/index.json/ package.

Why that package exists is left as an exercise to the user.

Change-Id: Idbad41867d3d3546a59fe0c4fa54c5be22e31438
This commit is contained in:
Michael Krotscheck 2016-04-15 08:18:54 -07:00
parent 255d8091e1
commit 8832f7c55e
No known key found for this signature in database
GPG Key ID: 20E618D878DE38AB

View File

@ -42,21 +42,20 @@ NameVirtualHost <%= @vhost_name %>:<%= @port %>
RewriteCond %{DOCUMENT_ROOT}/wheel/$1/$2/$2$3 -d RewriteCond %{DOCUMENT_ROOT}/wheel/$1/$2/$2$3 -d
RewriteRule ^/wheel/([^/]+)/([^/])([^/]*)(/.*)?$ /wheel/$1/$2/$2$3$4 [L] RewriteRule ^/wheel/([^/]+)/([^/])([^/]*)(/.*)?$ /wheel/$1/$2/$2$3$4 [L]
<Directory <%= @docroot %>/npm/> # npm's URL's are:
# /npm/-/index.json
# /npm/a/aabc/index.json
# /npm/a/aabc/latest/index.json
# /npm/a/aabc/-/aabc-0.0.0.tgz
RewriteCond %{REQUEST_URI} ^/npm/([^/])([^/]*)
RewriteCond %{DOCUMENT_ROOT}/npm/$1/$1$2 -d
RewriteRule ^/npm/([^/])([^/]*)(/.*)?$ /npm/$1/$1$2$3 [L]
<DirectoryMatch "<%= @docroot %>\/npm\/[^/]+\/.*">
DirectoryIndex index.json DirectoryIndex index.json
# npm's URL's are:
# /npm/-/index.json
# /npm/a/aabc/index.json
# /npm/a/aabc/latest/index.json
# /npm/a/aabc/-/aabc-0.0.0.tgz
RewriteCond %{REQUEST_URI} ^/npm/([^/])([^/]*)
RewriteCond %{DOCUMENT_ROOT}/npm/$1/$1$2 -d
RewriteRule ^([^/])([^/]*)(/.*)?$ $1/$1$2$3 [L]
AddOutputFilterByType SUBSTITUTE application/json AddOutputFilterByType SUBSTITUTE application/json
Substitute "s|http://localhost|http://<%= @srvname %>/npm|ni" Substitute "s|http://localhost|http://<%= @srvname %>/npm|ni"
</Directory> </DirectoryMatch>
ErrorLog /var/log/<%= scope.lookupvar("httpd::params::apache_name") %>/<%= @name %>_error.log ErrorLog /var/log/<%= scope.lookupvar("httpd::params::apache_name") %>/<%= @name %>_error.log
LogLevel warn LogLevel warn