File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed 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,39 @@ 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+ let id ;
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+ }
707745
708746// Webpack will replace 'require' with '__webpack_require__'
709747// '__non_webpack_require__' is a proxy to Node 'require'
You can’t perform that action at this time.
0 commit comments