Skip to content

Commit c0e2212

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 682b900 commit c0e2212

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
@@ -274,6 +274,11 @@ export function app() {
274274
*/
275275
server.get('/app/client/health', clientHealthCheck);
276276

277+
/**
278+
* Redirecting old manifest
279+
*/
280+
server.get('/json/iiif/**/manifest', redirectManifest);
281+
277282
/**
278283
* Default sending all incoming requests to ngApp() function, after first checking for a cached
279284
* copy of the page (see cacheCheck())
@@ -704,6 +709,38 @@ function healthCheck(req, res) {
704709
});
705710
}
706711

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

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

0 commit comments

Comments
 (0)