Skip to content

Commit

Permalink
Added a config switch for autoindexing and sorted out precedence with…
Browse files Browse the repository at this point in the history
… ocfl_index_files
  • Loading branch information
Mike Lynch authored and Mike Lynch committed Feb 4, 2020
1 parent 8f27b0d commit 13c5e33
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ Requires nginx with the njs JavaScript extension installed.

Components: a solr container and an nginx-ocfl container.


## Roadmap

### Automated test
### Authentication and authorisation

### Automated tests

### Versions

Expand Down
12 changes: 6 additions & 6 deletions conf.d/ocfl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ server {


set $ocfl_files /etc/share/nginx/html/ocfl;

location /trees_ocfl/ {
autoindex on;
root $ocfl_files;
}
set $ocfl_versions on;

location /trees/ {
set $ocfl_repo trees_ocfl;
set $ocfl_path trees;
set $ocfl_versions on;
set $ocfl_index_file ro-crate-preview.html;
set $ocfl_autoindex on;
js_content ocfl;
}

location /trees_ocfl/ {
root $ocfl_files;
}

location /solr/ {
proxy_pass http://solr:8983/solr/migrate_ocfl/;
Expand Down
7 changes: 5 additions & 2 deletions doc/ocfl-nginx.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ These can be configured for the whole server (all repos) or for individual repos

### $ocfl_index_file

This is the equivalent of the nginx `index` directive. If a file with this name is found in the path (and exists in
the requested version) it will be returned by default.
This is the equivalent of the nginx `index` directive. If a file with this name is found in the path (and exists in the requested version) it will be returned by default. If no such file is found, a 404 error is returned.

### $ocfl_autoindex

This is the equivalent of the nginx `autoindex` directive. If it is set to `on`, a directory listing will be generated from the OCFL object inventory.json file for any URL with no content or a path ending in '/'. `$ocfl_index_file` takes precedence over this setting: if the `$ocfl_index_file` is configured but not found, an autoindex listing will not be generated as a fallback.

### $ocfl_versions

Expand Down
8 changes: 5 additions & 3 deletions js/ocfl.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ function ocfl(req) {
var ocfl_repo = req.variables.ocfl_repo;
var ocfl_files = req.variables.ocfl_files;
var index_file = req.variables.ocfl_index_file || '';
var allow_autoindex = req.variables.ocfl_autoindex || '';
var ocfl_versions = req.variables.ocfl_versions;


var pattern = new RegExp(url_path + '/([^/\\.]+)(\\.v\\d+)?/([^?]*)(\\?.*)?$');
var match = req.uri.match(pattern);
if( !match ) {
Expand All @@ -32,6 +32,9 @@ function ocfl(req) {
if( ocfl_versions !== "on" ) {
v = undefined
}
if( index_file !== '' ) {
allow_autoindex = '';
}
var inv = load_inventory(req, ocfl_files + '/' + opath);
if( ! inv ) {
req.error("Couldn't load inventory for " + object);
Expand All @@ -50,8 +53,7 @@ function ocfl(req) {
req.error("Couldn't find version " + v);
req.internalRedirect("/404.html");
}

if( content === '' || content.slice(-1) === '/' ) {
if( allow_autoindex === 'on' && ( content === '' || content.slice(-1) === '/' ) ) {
auto_index(ocfl_repo, req, oid, inv, v, content);
} else {
var vpath = version(req, oid, inv, v, content);
Expand Down

0 comments on commit 13c5e33

Please sign in to comment.