diff --git a/Dockerfile b/Dockerfile index f6ff66e..d7279f9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,4 +7,6 @@ COPY conf.d/ocfl.conf /etc/nginx/conf.d RUN mkdir -p /etc/nginx/js COPY js/ocfl.js /etc/nginx/js RUN mkdir -p /etc/share/nginx/html/assets -COPY assets/* /etc/share/nginx/html/assets \ No newline at end of file +COPY assets/* /etc/share/nginx/html/assets +RUN mkdir -p /etc/share/nginx/html/error +COPY error/* /etc/share/nginx/html/error \ No newline at end of file diff --git a/conf.d/ocfl.conf b/conf.d/ocfl.conf index b2533eb..a91a1f7 100644 --- a/conf.d/ocfl.conf +++ b/conf.d/ocfl.conf @@ -11,10 +11,17 @@ server { set $ocfl_autoindex ro-crate-preview.html; set $ocfl_repo_index index.json; + set $ocfl_err_not_found /error/404.html; + set $ocfl_err_pending /error/pending.html; + location /assets/ { root /etc/share/nginx/html; } + location /error/ { + root /etc/share/nginx/html; + } + location /repo/ { set $ocfl_repo repo_ocfl; set $ocfl_solr /solr/ocflcore; diff --git a/error/404.html b/error/404.html new file mode 100644 index 0000000..af44963 --- /dev/null +++ b/error/404.html @@ -0,0 +1,12 @@ + + + URL not found + + + + +

404 not found

+ + + + \ No newline at end of file diff --git a/error/pending.html b/error/pending.html new file mode 100644 index 0000000..225dc3f --- /dev/null +++ b/error/pending.html @@ -0,0 +1,14 @@ + + + URL Pending + + + + +

Pending

+ +

The resource you are looking for will show up here eventually. Please try again later.

+ + + + \ No newline at end of file diff --git a/js/ocfl.js b/js/ocfl.js index 2fb4912..a860d60 100644 --- a/js/ocfl.js +++ b/js/ocfl.js @@ -19,7 +19,7 @@ function ocfl(req) { if( !repo ) { req.error("Couldn't find match for " + req.uri); - req.internalRedirect("/50x.html"); + req.internalRedirect(req.variables.ocfl_err_not_found); return; } @@ -84,7 +84,7 @@ function ocfl_object(req, repo, oidv, content) { var match = oidv.match(pattern); if( !match ) { req.error("Couldn't match oid " + oidv); - req.return(440, "Resource not found"); + req.internalRedirect(req.variables.ocfl_err_not_found); return } @@ -126,11 +126,14 @@ function ocfl_object(req, repo, oidv, content) { req.internalRedirect(newroute); } else { req.error("Version not found"); - req.internalRedirect("/404.html"); + req.internalRedirect(req.variables.ocfl_err_not_found); } } else { + // if the oid is well-formed but not in the index, assume + // that it's on its way and redirect to a 'come back later' + // page req.error("OID " + oid + " not found in index"); - req.internalRedirect("/404.html"); + req.internalRedirect(req.variables.ocfl_err_pending); } }); @@ -269,54 +272,3 @@ function load_inventory(req, object) { - - -// adapted from npm pairtree - - -function stringToUtf8ByteArray (str) { - str = str.replace(/\r\n/g, '\n'); - var out = [], p = 0; - for (var i = 0; i < str.length; i++) { - var c = str.charCodeAt(i); - if (c < 128) { - out[p++] = c; - } else if (c < 2048) { - out[p++] = (c >> 6) | 192; - out[p++] = (c & 63) | 128; - } else { - out[p++] = (c >> 12) | 224; - out[p++] = ((c >> 6) & 63) | 128; - out[p++] = (c & 63) | 128; - } - } - return out; -} - -function pairtree(id, separator) { - separator = separator || '/'; - id = id.replace(/[\"*+,<=>?\\^|]|[^\x21-\x7e]/g, function(c) { - c = stringToUtf8ByteArray(c); - var ret = ''; - for (var i=0, l=c.length; i 255) return ''; // drop characters greater than ff - //return '^' + c.toString(16); - return ret; - }); - id = id.replace(/\//g, '=').replace(/:/g, '+').replace(/\./g, ','); - var path = separator; - while (id) { - path += id.substr(0, 2) + separator; - id = id.substr(2); - } - return path; -} - - - - - -