1- const log = require ( "@ui5/logger" ) . getLogger ( "proxyConfiguration" ) ;
2- const { resourceFactory} = require ( "@ui5/fs" ) ;
1+ const log = require ( "@ui5/logger" ) . getLogger ( "server:proxyConfiguration" ) ;
32
43const proxyConfigurations = { } ;
54
@@ -10,6 +9,9 @@ function addConfiguration(name, proxyConfig) {
109 if ( proxyConfigurations [ name ] ) {
1110 throw new Error ( `proxyConfiguration: A configuration with name ${ name } is already known` ) ;
1211 }
12+ if ( proxyConfig . rewriteRootPaths ) {
13+ throw new Error ( `Proxy Configuration ${ name } must not define "rewriteRootPaths"` ) ;
14+ }
1315
1416 if ( ! proxyConfig . destination ) {
1517 proxyConfig . destination = { } ;
@@ -26,23 +28,65 @@ async function getConfigurationForProject(project) {
2628 throw new Error ( `Found multiple proxy configurations. ` +
2729 `This is not yet supported.` ) ; // TODO
2830 }
31+
32+ log . verbose ( `Applying proxy configuration ${ configNames [ 0 ] } to project ${ project . metadata . name } ...` ) ;
2933 const config = JSON . parse ( JSON . stringify ( proxyConfigurations [ configNames [ 0 ] ] ) ) ;
34+ config . rewriteRootPaths = { } ;
35+
36+ if ( config . destination . ui5Root && ! config . appOnly ) {
37+ log . verbose ( `Using configured "destination.ui5Root": ${ config . destination . ui5Root } ` ) ;
38+ config . rewriteRootPaths [ config . destination . ui5Root ] = {
39+ rewriteTo : ""
40+ } ;
41+ }
42+
43+ mapProjectDependencies ( project , ( proj ) => {
44+ if ( proj . specVersion !== "1.1a" ) {
45+ log . warn ( `Project ${ project . metadata . name } defines specification version ${ proj . specVersion } . ` +
46+ `Some proxy configuration features require projects to define specification version 1.1a` ) ;
47+ }
48+ log . verbose ( `Using ABAP URI ${ proj . metadata . abapUri } from metadata of project ${ proj . metadata . name } ` ) ;
49+ let prefix = "" ;
50+ if ( proj . type !== "application" ) {
51+ if ( project . resources . pathMappings [ "/resources" ] ) {
52+ // If the project defines a /resources path mapping,
53+ // we expect this to match the ABAP URI deployment path
54+ prefix += "/resources/" ;
55+
56+ // If this is not an application and there is no /resources path mapping, somebody does something wild
57+ // and hopefully knows what he/she does
58+ }
59+ prefix += proj . metadata . namespace ;
60+ }
61+ config . rewriteRootPaths [ proj . metadata . abapUri ] = {
62+ rewriteTo : prefix
63+ } ;
64+ } ) ;
3065
31- const { source} = resourceFactory . createCollectionsForTree ( project ) ;
32- const manifestResource = await source . byPath ( "/manifest.json" ) ;
33- if ( manifestResource ) {
34- const manifest = JSON . parse ( await manifestResource . getBuffer ( ) ) ;
35- if ( manifest [ "sap.platform.abap" ] && manifest [ "sap.platform.abap" ] . uri ) {
36- log . verbose ( `Using sap.platform.abap URI configuration as application root ` +
37- `path: ${ manifest [ "sap.platform.abap" ] . uri } ` ) ;
38- config . destination . appRoot = manifest [ "sap.platform.abap" ] . uri ;
66+ if ( log . isLevelEnabled ( "verbose" ) ) {
67+ log . verbose ( `Configured ${ config . rewriteRootPaths . length } root paths to rewrite for ` +
68+ `project ${ project . metadata . name } ;` ) ;
69+ for ( const abapUri in config . rewriteRootPaths ) {
70+ if ( config . rewriteRootPaths . hasOwnProperty ( abapUri ) ) {
71+ if ( config . rewriteRootPaths [ abapUri ] . rewriteTo ) {
72+ log . verbose ( `Rewriting ${ abapUri } to ${ config . rewriteRootPaths [ abapUri ] . rewriteTo } ` ) ;
73+ } else {
74+ log . verbose ( `Rewriting ${ abapUri } ` ) ;
75+ }
76+ }
3977 }
4078 }
41- log . verbose ( `UI5 root path configured as: ${ config . destination . ui5Root } ` ) ;
4279
4380 return config ;
4481}
4582
83+ function mapProjectDependencies ( tree , handler ) {
84+ handler ( tree ) ;
85+ tree . dependencies . map ( ( dep ) => {
86+ mapProjectDependencies ( dep , handler ) ;
87+ } ) ;
88+ }
89+
4690module . exports = {
4791 addConfiguration,
4892 getConfigurationForProject
0 commit comments