@@ -67,6 +67,8 @@ extendEnvironmentWithAppConfig(environment, appConfig);
6767// The Express app is exported so that it can be used by serverless Functions.
6868export function app ( ) {
6969
70+ const router = express . Router ( ) ;
71+
7072 /*
7173 * Create a new express application
7274 */
@@ -138,7 +140,11 @@ export function app() {
138140 /**
139141 * Proxy the sitemaps
140142 */
141- server . use ( '/sitemap**' , createProxyMiddleware ( { target : `${ environment . rest . baseUrl } /sitemaps` , changeOrigin : true } ) ) ;
143+ router . use ( '/sitemap**' , createProxyMiddleware ( {
144+ target : `${ environment . rest . baseUrl } /sitemaps` ,
145+ pathRewrite : path => path . replace ( environment . ui . nameSpace , '/' ) ,
146+ changeOrigin : true
147+ } ) ) ;
142148
143149 /**
144150 * Checks if the rateLimiter property is present
@@ -157,7 +163,7 @@ export function app() {
157163 * Serve static resources (images, i18n messages, …)
158164 * Handle pre-compressed files with [express-static-gzip](https://github.com/tkoenig89/express-static-gzip)
159165 */
160- server . get ( '*.*' , cacheControl , expressStaticGzip ( DIST_FOLDER , {
166+ router . get ( '*.*' , cacheControl , expressStaticGzip ( DIST_FOLDER , {
161167 index : false ,
162168 enableBrotli : true ,
163169 orderPreference : [ 'br' , 'gzip' ] ,
@@ -166,10 +172,12 @@ export function app() {
166172 /*
167173 * Fallthrough to the IIIF viewer (must be included in the build).
168174 */
169- server . use ( '/iiif' , express . static ( IIIF_VIEWER , { index :false } ) ) ;
175+ router . use ( '/iiif' , express . static ( IIIF_VIEWER , { index : false } ) ) ;
170176
171177 // Register the ngApp callback function to handle incoming requests
172- server . get ( '*' , ngApp ) ;
178+ router . get ( '*' , ngApp ) ;
179+
180+ server . use ( environment . ui . nameSpace , router ) ;
173181
174182 return server ;
175183}
@@ -203,13 +211,25 @@ function ngApp(req, res) {
203211 if ( hasValue ( err ) ) {
204212 console . warn ( 'Error details : ' , err ) ;
205213 }
206- res . sendFile ( DIST_FOLDER + '/index.html' ) ;
214+ res . render ( indexHtml , {
215+ req,
216+ providers : [ {
217+ provide : APP_BASE_HREF ,
218+ useValue : req . baseUrl
219+ } ]
220+ } ) ;
207221 }
208222 } ) ;
209223 } else {
210224 // If preboot is disabled, just serve the client
211225 console . log ( 'Universal off, serving for direct CSR' ) ;
212- res . sendFile ( DIST_FOLDER + '/index.html' ) ;
226+ res . render ( indexHtml , {
227+ req,
228+ providers : [ {
229+ provide : APP_BASE_HREF ,
230+ useValue : req . baseUrl
231+ } ]
232+ } ) ;
213233 }
214234}
215235
0 commit comments