From 13c5e335f1211845ed132fc67d24677505891737 Mon Sep 17 00:00:00 2001 From: Mike Lynch Date: Tue, 4 Feb 2020 15:22:42 +1100 Subject: [PATCH] Added a config switch for autoindexing and sorted out precedence with ocfl_index_files --- README.md | 5 +++-- conf.d/ocfl.conf | 12 ++++++------ doc/ocfl-nginx.md | 7 +++++-- js/ocfl.js | 8 +++++--- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index a57f44a..dd77c90 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/conf.d/ocfl.conf b/conf.d/ocfl.conf index 9242f2d..28811be 100644 --- a/conf.d/ocfl.conf +++ b/conf.d/ocfl.conf @@ -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/; diff --git a/doc/ocfl-nginx.md b/doc/ocfl-nginx.md index be4d961..b9ffde9 100644 --- a/doc/ocfl-nginx.md +++ b/doc/ocfl-nginx.md @@ -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 diff --git a/js/ocfl.js b/js/ocfl.js index c9deba2..02b9325 100644 --- a/js/ocfl.js +++ b/js/ocfl.js @@ -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 ) { @@ -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); @@ -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);