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 @@ -255,6 +255,11 @@ export function app() {
255255 */
256256 server . get ( '/app/client/health' , clientHealthCheck ) ;
257257
258+ /**
259+ * Redirecting old manifest
260+ */
261+ server . get ( '/json/iiif/**/manifest' , redirectManifest ) ;
262+
258263 /**
259264 * Default sending all incoming requests to ngApp() function, after first checking for a cached
260265 * copy of the page (see cacheCheck())
@@ -721,6 +726,39 @@ function healthCheck(req, res) {
721726 } ) ;
722727}
723728
729+ /*
730+ * The callback function to redirect old manifest
731+ */
732+ function redirectManifest ( req , res ) {
733+ console . info ( 'Redirecting old manifest' ) ;
734+ const url = req . url ;
735+ const regex = / j s o n \/ i i i f \/ ( [ ^ \/ ] + \/ [ ^ \/ ] + ) (?: \/ ( [ ^ \/ ] + ) ) ? \/ m a n i f e s t / ;
736+ const match = url . match ( regex ) ;
737+ let handle ;
738+ let id ;
739+
740+ if ( match ) {
741+ handle = match [ 1 ] ;
742+ const baseUrl = `${ environment . rest . baseUrl } /api/pid/find?id=${ handle } ` ;
743+ axios . get ( baseUrl )
744+ . then ( ( response ) => {
745+ if ( response . status === 200 ) {
746+ const newUrl = `${ environment . rest . baseUrl } /iiif/${ response . data . id } /manifest` ;
747+ console . info ( 'Manifest found, redirect to ' , newUrl ) ;
748+ res . redirect ( newUrl ) ;
749+ }
750+ } )
751+ . catch ( ( error ) => {
752+ res . status ( error . response . status ) . send ( {
753+ error : error . message
754+ } ) ;
755+ } ) ;
756+ } else {
757+ res . status ( 422 ) . send ( {
758+ error : 'Wrong handle'
759+ } ) ;
760+ }
761+ }
724762
725763// Webpack will replace 'require' with '__webpack_require__'
726764// '__non_webpack_require__' is a proxy to Node 'require'
You can’t perform that action at this time.
0 commit comments