1
1
const log = require ( "@ui5/logger" ) . getLogger ( "server:middleware:proxyRewrite" ) ;
2
2
3
- function createMiddleware ( { resources, configuration, cdnUrl} ) {
3
+ function createMiddleware ( { resources, middlewareUtil , configuration, cdnUrl} ) {
4
4
const rewriteRootPaths = configuration . rewriteRootPaths ;
5
5
6
6
const cacheBusterRegex = / ~ .* ~ [ A - Z 0 - 9 ] ? \/ ? / ;
7
7
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;
8
8
9
9
return function proxyRewrite ( req , res , next ) {
10
+ const pathname = middlewareUtil . getPathname ( req ) ;
10
11
const rewriteApplicable = Object . keys ( rewriteRootPaths ) . some ( ( resourceRootPath ) => {
11
- return req . path . indexOf ( resourceRootPath ) !== - 1 ;
12
+ return pathname . indexOf ( resourceRootPath ) !== - 1 ;
12
13
} ) ;
13
14
14
15
if ( ! rewriteApplicable ) {
@@ -17,15 +18,15 @@ function createMiddleware({resources, configuration, cdnUrl}) {
17
18
return ;
18
19
}
19
20
20
- log . verbose ( `Normalizing ${ req . path } ...` ) ;
21
+ log . verbose ( `Normalizing ${ pathname } ...` ) ;
21
22
// Normalize URL
22
- normalizeRequestPath ( req . path )
23
+ normalizeRequestPath ( pathname )
23
24
. catch ( ( err ) => {
24
- log . error ( `Failed to normalize ${ req . path } . Error ${ err . message } ` ) ;
25
+ log . error ( `Failed to normalize ${ pathname } . Error ${ err . message } ` ) ;
25
26
return "" ;
26
27
} )
27
28
. then ( ( normalizedUrl ) => {
28
- req . url = req . url . replace ( req . path , normalizedUrl ) ;
29
+ req . url = req . url . replace ( pathname , normalizedUrl ) ;
29
30
log . verbose ( `Normalized ${ req . originalUrl } ` ) ;
30
31
log . verbose ( ` to ${ req . url } ` ) ; // will be used for internal resolution
31
32
handleSpecialRequests ( req , res , next ) ;
0 commit comments