11const log = require ( "@ui5/logger" ) . getLogger ( "server:middleware:proxyRewrite" ) ;
22
3- function createMiddleware ( { resources, configuration, cdnUrl} ) {
3+ function createMiddleware ( { resources, middlewareUtil , configuration, cdnUrl} ) {
44 const rewriteRootPaths = configuration . rewriteRootPaths ;
55
66 const cacheBusterRegex = / ~ .* ~ [ A - Z 0 - 9 ] ? \/ ? / ;
77 const preloadRegex = / ^ .* (?: C o m p o n e n t - p r e l o a d \. j s | l i b r a r y - p r e l o a d \. j s | l i b r a r y - p r e l o a d \. j s o n ) $ / i;
88
99 return function proxyRewrite ( req , res , next ) {
10+ const pathname = middlewareUtil . getPathname ( req ) ;
1011 const rewriteApplicable = Object . keys ( rewriteRootPaths ) . some ( ( resourceRootPath ) => {
11- return req . path . indexOf ( resourceRootPath ) !== - 1 ;
12+ return pathname . indexOf ( resourceRootPath ) !== - 1 ;
1213 } ) ;
1314
1415 if ( ! rewriteApplicable ) {
@@ -17,15 +18,15 @@ function createMiddleware({resources, configuration, cdnUrl}) {
1718 return ;
1819 }
1920
20- log . verbose ( `Normalizing ${ req . path } ...` ) ;
21+ log . verbose ( `Normalizing ${ pathname } ...` ) ;
2122 // Normalize URL
22- normalizeRequestPath ( req . path )
23+ normalizeRequestPath ( pathname )
2324 . catch ( ( err ) => {
24- log . error ( `Failed to normalize ${ req . path } . Error ${ err . message } ` ) ;
25+ log . error ( `Failed to normalize ${ pathname } . Error ${ err . message } ` ) ;
2526 return "" ;
2627 } )
2728 . then ( ( normalizedUrl ) => {
28- req . url = req . url . replace ( req . path , normalizedUrl ) ;
29+ req . url = req . url . replace ( pathname , normalizedUrl ) ;
2930 log . verbose ( `Normalized ${ req . originalUrl } ` ) ;
3031 log . verbose ( ` to ${ req . url } ` ) ; // will be used for internal resolution
3132 handleSpecialRequests ( req , res , next ) ;
0 commit comments