1
- const log = require ( "@ui5/logger" ) . getLogger ( "proxyConfiguration" ) ;
2
- const { resourceFactory} = require ( "@ui5/fs" ) ;
1
+ const log = require ( "@ui5/logger" ) . getLogger ( "server:proxyConfiguration" ) ;
3
2
4
3
const proxyConfigurations = { } ;
5
4
@@ -10,6 +9,9 @@ function addConfiguration(name, proxyConfig) {
10
9
if ( proxyConfigurations [ name ] ) {
11
10
throw new Error ( `proxyConfiguration: A configuration with name ${ name } is already known` ) ;
12
11
}
12
+ if ( proxyConfig . rewriteRootPaths ) {
13
+ throw new Error ( `Proxy Configuration ${ name } must not define "rewriteRootPaths"` ) ;
14
+ }
13
15
14
16
if ( ! proxyConfig . destination ) {
15
17
proxyConfig . destination = { } ;
@@ -26,23 +28,65 @@ async function getConfigurationForProject(project) {
26
28
throw new Error ( `Found multiple proxy configurations. ` +
27
29
`This is not yet supported.` ) ; // TODO
28
30
}
31
+
32
+ log . verbose ( `Applying proxy configuration ${ configNames [ 0 ] } to project ${ project . metadata . name } ...` ) ;
29
33
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
+ } ) ;
30
65
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
+ }
39
77
}
40
78
}
41
- log . verbose ( `UI5 root path configured as: ${ config . destination . ui5Root } ` ) ;
42
79
43
80
return config ;
44
81
}
45
82
83
+ function mapProjectDependencies ( tree , handler ) {
84
+ handler ( tree ) ;
85
+ tree . dependencies . map ( ( dep ) => {
86
+ mapProjectDependencies ( dep , handler ) ;
87
+ } ) ;
88
+ }
89
+
46
90
module . exports = {
47
91
addConfiguration,
48
92
getConfigurationForProject
0 commit comments