Skip to content

Commit

Permalink
Added error and pending HTML pages to the Docker image for ocfl-nginx
Browse files Browse the repository at this point in the history
  • Loading branch information
spikelynch committed Nov 4, 2019
1 parent fd8d6e9 commit a85450c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 56 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
COPY assets/* /etc/share/nginx/html/assets
RUN mkdir -p /etc/share/nginx/html/error
COPY error/* /etc/share/nginx/html/error
7 changes: 7 additions & 0 deletions conf.d/ocfl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions error/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html>
<head>
<title>URL not found</title>
<link rel="stylesheet" type="text/css" href="/assets/ocfl.css">
</head>

<body>
<h1>404 not found</h1>

</body>

</html>
14 changes: 14 additions & 0 deletions error/pending.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html>
<head>
<title>URL Pending</title>
<link rel="stylesheet" type="text/css" href="/assets/ocfl.css">
</head>

<body>
<h1>Pending</h1>

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

</body>

</html>
62 changes: 7 additions & 55 deletions js/ocfl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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);
}

});
Expand Down Expand Up @@ -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<l; i++) {
ret += '^' + c[i].toString(16);
}
//c = c.charCodeAt(0);
//if (c > 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;
}






0 comments on commit a85450c

Please sign in to comment.