Skip to content

Commit 196ace6

Browse files
atarix83Mattia Vianelli
authored andcommitted
[DSC-2281] Add express route rule for redirecting old manifest url to new one
(cherry picked from commit d7e89dceb40bb02c8cc842f579dde17088fdb45e)
1 parent 87686fc commit 196ace6

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

server.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@ export function app() {
254254
*/
255255
server.get('/app/client/health', clientHealthCheck);
256256

257+
/**
258+
* Redirecting old manifest
259+
*/
260+
server.get('/json/iiif/**/manifest', redirectManifest);
261+
257262
/**
258263
* Default sending all incoming requests to ngApp() function, after first checking for a cached
259264
* copy of the page (see cacheCheck())
@@ -705,6 +710,38 @@ function healthCheck(req, res) {
705710
});
706711
}
707712

713+
/*
714+
* The callback function to redirect old manifest
715+
*/
716+
function redirectManifest(req, res) {
717+
console.info('Redirecting old manifest');
718+
const url = req.url;
719+
const regex = /json\/iiif\/(.+?)\/manifest/;
720+
const match = url.match(regex);
721+
let handle;
722+
723+
if (match) {
724+
handle = match[1];
725+
const baseUrl = `${environment.rest.baseUrl}/api/pid/find?id=${handle}`;
726+
axios.get(baseUrl)
727+
.then((response) => {
728+
if (response.status === 200) {
729+
const newUrl = `${environment.rest.baseUrl}/iiif/${response.data.id}/manifest`;
730+
console.info('Manifest found, redirect to ', newUrl);
731+
res.redirect(newUrl);
732+
}
733+
})
734+
.catch((error) => {
735+
res.status(error.response.status).send({
736+
error: error.message
737+
});
738+
});
739+
} else {
740+
res.status(422).send({
741+
error: 'Wrong handle'
742+
});
743+
}
744+
}
708745

709746
// Webpack will replace 'require' with '__webpack_require__'
710747
// '__non_webpack_require__' is a proxy to Node 'require'

0 commit comments

Comments
 (0)