File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 = / j s o n \/ i i i f \/ ( .+ ?) \/ m a n i f e s t / ;
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'
You can’t perform that action at this time.
0 commit comments