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