dev-approuter 0.1.16 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +16 -15
- package/lib/devApprouter.js +29 -26
- package/lib/helpers.js +4 -4
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.1.18](https://github.com/ui5-community/ui5-ecosystem-showcase/compare/dev-approuter@0.1.17...dev-approuter@0.1.18) (2023-09-15)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* prevent side-effects for combined scenarios ([#842](https://github.com/ui5-community/ui5-ecosystem-showcase/issues/842)) ([36aaa5f](https://github.com/ui5-community/ui5-ecosystem-showcase/commit/36aaa5f8d8b8404725250664704a560229055943))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [0.1.17](https://github.com/ui5-community/ui5-ecosystem-showcase/compare/dev-approuter@0.1.16...dev-approuter@0.1.17) (2023-09-14)
|
|
18
|
+
|
|
19
|
+
**Note:** Version bump only for package dev-approuter
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
## [0.1.16](https://github.com/ui5-community/ui5-ecosystem-showcase/compare/dev-approuter@0.1.15...dev-approuter@0.1.16) (2023-09-13)
|
|
7
26
|
|
|
8
27
|
**Note:** Version bump only for package dev-approuter
|
package/README.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
> :wave: This is a **community project** and there is no official support for this package! Feel free to use it, open issues, contribute, and help answering questions.
|
|
4
4
|
|
|
5
|
-
The `dev-approuter` is a dev time wrapper for the [SAP Application Router](https://www.npmjs.com/package/@sap/approuter) that can serve [UI5](https://ui5.sap.com/) and [SAP CAP](https://cap.cloud.sap/docs/) apps that are added as (dev)dependencies to the approuter's `package.json`. A few key notes to begin with:
|
|
5
|
+
The `dev-approuter` is a dev time wrapper for the [SAP Application Router](https://www.npmjs.com/package/@sap/approuter) that can serve [UI5](https://ui5.sap.com/) and [SAP Cloud Application Programming Model (CAP)](https://cap.cloud.sap/docs/) apps that are added as (dev)dependencies to the approuter's `package.json`. A few key notes to begin with:
|
|
6
6
|
- The `dev-approuter` utilizes the [SAP Application Router's extension API](https://help.sap.com/docs/btp/sap-business-technology-platform/extension-api-of-application-router) by adding UI5 servers as extensions - providing the full [UI5 Tooling](https://sap.github.io/ui5-tooling/v3/) experience.
|
|
7
|
-
- A linked SAP
|
|
7
|
+
- A linked SAP CDS app is started on a different port - this is to mimic a deployed architecture. The corresponding destination is automatically created for you.
|
|
8
8
|
- In order to safely separate development configuration from productive code, the `dev-approuter` introduces the concept of the `xs-dev.json` - think of it as an extension to the [`xs-app.json`](https://help.sap.com/docs/btp/sap-business-technology-platform/routing-configuration-file).
|
|
9
9
|
- As the name suggests, the `dev-approuter` is for development only and not meant to be used in production.
|
|
10
10
|
|
|
@@ -14,7 +14,7 @@ The `dev-approuter` is a dev time wrapper for the [SAP Application Router](https
|
|
|
14
14
|
2. [Starting the `dev-approuter`](#starting-the-dev-approuter)
|
|
15
15
|
3. [Adding and serving apps](#adding-and-serving-apps)
|
|
16
16
|
- [UI5 apps](#ui5-apps)
|
|
17
|
-
- [SAP
|
|
17
|
+
- [SAP CDS server](#sap-cds-server)
|
|
18
18
|
4. [The `xs-dev.json` file](#the-xs-devjson-file)
|
|
19
19
|
5. [Using the `dev-approuter` and SAP Application Router simultaneously](#using-the-dev-approuter-and-sap-approuter-simultaneously)
|
|
20
20
|
6. [Extending the `dev-approuter`](#extending-the-dev-approuter)
|
|
@@ -58,7 +58,7 @@ The `dev-approuter` is a wrapper for the SAP Application Router, meaning your cu
|
|
|
58
58
|
|
|
59
59
|
## Adding and serving apps
|
|
60
60
|
|
|
61
|
-
To add a UI5 or SAP
|
|
61
|
+
To add a UI5 or SAP CDS app to the `dev-approuter`, add it to the `devDependencies` section of your approuter's `package.json` file:
|
|
62
62
|
|
|
63
63
|
```json
|
|
64
64
|
{
|
|
@@ -66,7 +66,7 @@ To add a UI5 or SAP CAP app to the `dev-approuter`, add it to the `devDependenci
|
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
...
|
|
68
68
|
"my-ui5-app": "path/to/ui5-app",
|
|
69
|
-
"my-
|
|
69
|
+
"my-cds-app": "path/to/cds-app"
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
```
|
|
@@ -81,23 +81,24 @@ metadata:
|
|
|
81
81
|
name: ui5-app # default mount path would be /ui5-app
|
|
82
82
|
type: application
|
|
83
83
|
customConfiguration:
|
|
84
|
-
|
|
84
|
+
cds-plugin-ui5:
|
|
85
|
+
mountPath: /my-custom-mount-path # overwrites the default mount path
|
|
85
86
|
```
|
|
86
87
|
|
|
87
88
|
The above configuration result in the UI5 app being available at `http://localhost:5000/my-custom-mount-path`.
|
|
88
89
|
|
|
89
|
-
### SAP
|
|
90
|
+
### SAP CDS server
|
|
90
91
|
|
|
91
|
-
SAP
|
|
92
|
+
SAP CDS server is started on a separate port (4004 by default, can be overwritten via `CDS_PORT`). The `dev-approuter` automatically creates a route and destination behind the scenes, so that you (and your UI5 apps) can reach your SAP CDS services directly at their service path, but through the `dev-approuter`, e.g. `http://localhost:5000/my-cds-service`.
|
|
92
93
|
|
|
93
|
-
There is no need manually create a destination for you SAP
|
|
94
|
+
There is no need manually create a destination for you SAP CDS app, unless you want to overwrite the [default destination configuration](./lib/helpers.js#L81-L85). In this case, create a new destination in a `default-env.json`. The destination's name has to match the module name as declared in the approuter's `devDependencies`:
|
|
94
95
|
|
|
95
96
|
```json
|
|
96
97
|
{
|
|
97
|
-
"
|
|
98
|
+
"CDS_PORT": 4005,
|
|
98
99
|
"destinations": [
|
|
99
100
|
{
|
|
100
|
-
"Name": "my-
|
|
101
|
+
"Name": "my-cds-app",
|
|
101
102
|
"Authentication": "NoAuthentication",
|
|
102
103
|
"ProxyType": "Internet",
|
|
103
104
|
"Type": "HTTP",
|
|
@@ -113,7 +114,7 @@ There is no need manually create a destination for you SAP CAP app, unless you w
|
|
|
113
114
|
|
|
114
115
|
The `dev-approuter` introduces the concept of an `xs-dev.json` file, which works like a regular [`xs-app.json`](https://help.sap.com/docs/btp/sap-business-technology-platform/routing-configuration-file) file, but is used by the `dev-approuter` exclusively (meaning it's ignored by the SAP Application Router). The idea behind this concept is to safely separate dev time configuration from productive code.
|
|
115
116
|
|
|
116
|
-
The `xs-dev.json` follows the same logic and syntax as the [`xs-app.json`](https://help.sap.com/docs/btp/sap-business-technology-platform/routing-configuration-file) file, but has one additional key feature: You can add a `dependency` to a `route`, which links it to a UI5 or SAP
|
|
117
|
+
The `xs-dev.json` follows the same logic and syntax as the [`xs-app.json`](https://help.sap.com/docs/btp/sap-business-technology-platform/routing-configuration-file) file, but has one additional key feature: You can add a `dependency` to a `route`, which links it to a UI5 or SAP CDS app.
|
|
117
118
|
|
|
118
119
|
Look at the following example `xs-dev.json` that defines different `authenticationType`s for different UI5 apps:
|
|
119
120
|
|
|
@@ -134,11 +135,11 @@ Look at the following example `xs-dev.json` that defines different `authenticati
|
|
|
134
135
|
}
|
|
135
136
|
```
|
|
136
137
|
|
|
137
|
-
Behind the scenes, the `dev-approuter` will resolve these "dependency routes" by adding the `source`, `target`, and `destination` properties to them. Be aware that exactly these properties get overwritten by the `dev-approuter` in case you use them together with `dependency`. The only exception are SAP
|
|
138
|
+
Behind the scenes, the `dev-approuter` will resolve these "dependency routes" by adding the `source`, `target`, and `destination` properties to them. Be aware that exactly these properties get overwritten by the `dev-approuter` in case you use them together with `dependency`. The only exception are SAP CDS dependencies, for which only the `destination` property gets overwritten by the `dev-approuter`.
|
|
138
139
|
|
|
139
140
|
## Using the `dev-approuter` and SAP Application Router simultaneously
|
|
140
141
|
|
|
141
|
-
If you choose to place your `dev-approuter` in the same directory as an SAP Application Router, which you will eventually deploy, you will have to remove the `devDependencies` section of the `package.json` before deployment. This is required because the SAP Application Router will not be able to install local dev dependencies (your UI5 and SAP
|
|
142
|
+
If you choose to place your `dev-approuter` in the same directory as an SAP Application Router, which you will eventually deploy, you will have to remove the `devDependencies` section of the `package.json` before deployment. This is required because the SAP Application Router will not be able to install local dev dependencies (your UI5 and SAP CDS apps) in the cloud. To achieve this, you could introduce a build step for the approuter, moving required files to a `dist/` folder and removing dev dependencies:
|
|
142
143
|
|
|
143
144
|
```json
|
|
144
145
|
"build": "mkdir -p dist && jq 'del(.devDependencies)' package.json > dist/package.json && cp xs-app.json dist/xs-app.json"
|
|
@@ -176,4 +177,4 @@ Any type of contribution (code contributions, pull requests, issues) to this set
|
|
|
176
177
|
|
|
177
178
|
## License
|
|
178
179
|
|
|
179
|
-
This work is [dual-licensed](../../LICENSE) under Apache 2.0 and the Derived Beer-ware License. The official license will be Apache 2.0 but finally you can choose between one of them if you use this work.
|
|
180
|
+
This work is [dual-licensed](../../LICENSE) under Apache 2.0 and the Derived Beer-ware License. The official license will be Apache 2.0 but finally you can choose between one of them if you use this work.
|
package/lib/devApprouter.js
CHANGED
|
@@ -6,10 +6,13 @@ const findUI5Modules = require("cds-plugin-ui5/lib/findUI5Modules");
|
|
|
6
6
|
const createPatchedRouter = require("cds-plugin-ui5/lib/createPatchedRouter");
|
|
7
7
|
const applyUI5Middleware = require("cds-plugin-ui5/lib/applyUI5Middleware");
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
const
|
|
9
|
+
const findCDSModules = require("ui5-middleware-cap/lib/findCDSModules");
|
|
10
|
+
const applyCDSMiddleware = require("ui5-middleware-cap/lib/applyCDSMiddleware");
|
|
11
11
|
|
|
12
|
-
const { parseConfig, applyDependencyConfig, addDestination,
|
|
12
|
+
const { parseConfig, applyDependencyConfig, addDestination, configureCDSRoute, configureUI5Route } = require("./helpers");
|
|
13
|
+
|
|
14
|
+
// marker that the dev-approuter is running
|
|
15
|
+
process.env["dev-approuter"] = true;
|
|
13
16
|
|
|
14
17
|
class DevApprouter {
|
|
15
18
|
constructor() {}
|
|
@@ -21,7 +24,7 @@ class DevApprouter {
|
|
|
21
24
|
* Here is a shorter summary:
|
|
22
25
|
* UI5 modules declared as (dev)dependencies are added as extensions
|
|
23
26
|
* using the extension API of the SAP Approuter.
|
|
24
|
-
*
|
|
27
|
+
* CDS modules declared as (dev)dependencies are started on a different port.
|
|
25
28
|
* Corresponding routes and destinations are automatically created.
|
|
26
29
|
* A custom `xs-dev.json` can be used to configure the dev approuter,
|
|
27
30
|
* so the productive configuration can be kept in the `xs-app.json`.
|
|
@@ -45,19 +48,19 @@ class DevApprouter {
|
|
|
45
48
|
const config = parseConfig();
|
|
46
49
|
const cwd = process.cwd();
|
|
47
50
|
|
|
48
|
-
// lookup the
|
|
49
|
-
let
|
|
50
|
-
const
|
|
51
|
-
if (
|
|
52
|
-
throw new Error(`Multiple
|
|
53
|
-
} else if (
|
|
54
|
-
|
|
51
|
+
// lookup the CDS server root
|
|
52
|
+
let cdsServerConfig;
|
|
53
|
+
const cdsModules = await findCDSModules({ cwd });
|
|
54
|
+
if (cdsModules.length > 1) {
|
|
55
|
+
throw new Error(`Multiple CDS modules found. The package dev-approuter can only handle one CDS module as dependency.`);
|
|
56
|
+
} else if (cdsModules.length === 1) {
|
|
57
|
+
cdsServerConfig = cdsModules[0];
|
|
55
58
|
}
|
|
56
59
|
|
|
57
|
-
// find all UI5 modules from the
|
|
60
|
+
// find all UI5 modules from the CDS server root and dependencies from the approuter
|
|
58
61
|
const ui5Modules = [...(await findUI5Modules({ cwd, skipLocalApps: true }))];
|
|
59
|
-
if (
|
|
60
|
-
ui5Modules.push(...(await findUI5Modules({ cwd:
|
|
62
|
+
if (cdsServerConfig) {
|
|
63
|
+
ui5Modules.push(...(await findUI5Modules({ cwd: cdsServerConfig.modulePath, skipDeps: true })));
|
|
61
64
|
}
|
|
62
65
|
|
|
63
66
|
// collect UI5 middlewares
|
|
@@ -74,7 +77,7 @@ class DevApprouter {
|
|
|
74
77
|
basePath: modulePath,
|
|
75
78
|
});
|
|
76
79
|
|
|
77
|
-
// mounting the router for the UI5 application to the
|
|
80
|
+
// mounting the router for the UI5 application to the CDS server
|
|
78
81
|
console.log(`Mounting ${mountPath} to UI5 app ${modulePath}`);
|
|
79
82
|
|
|
80
83
|
let middlewareMountPath;
|
|
@@ -98,31 +101,31 @@ class DevApprouter {
|
|
|
98
101
|
});
|
|
99
102
|
}
|
|
100
103
|
|
|
101
|
-
// start
|
|
102
|
-
if (
|
|
103
|
-
const { modulePath, moduleId } =
|
|
104
|
+
// start CDS server on different port
|
|
105
|
+
if (cdsServerConfig) {
|
|
106
|
+
const { modulePath, moduleId } = cdsServerConfig;
|
|
104
107
|
|
|
105
|
-
// start
|
|
108
|
+
// start CDS server on different port
|
|
106
109
|
const app = express();
|
|
107
|
-
const { servicesPaths } = await
|
|
108
|
-
app.listen(process.env.
|
|
109
|
-
console.log(`
|
|
110
|
+
const { servicesPaths } = await applyCDSMiddleware(app, { root: modulePath, cwd });
|
|
111
|
+
app.listen(process.env.CDS_PORT || 4004, () => {
|
|
112
|
+
console.log(`CDS server started at: http://localhost:${process.env.CDS_PORT || 4004}`);
|
|
110
113
|
});
|
|
111
114
|
|
|
112
|
-
// create route if
|
|
115
|
+
// create route if CDS module is not referenced in xs-dev.json/xs-app.json
|
|
113
116
|
if (!config.dependencyRoutes[moduleId]) {
|
|
114
117
|
const route = {
|
|
115
118
|
dependency: moduleId,
|
|
116
119
|
authenticationType: "none",
|
|
117
120
|
};
|
|
118
121
|
config.routes.unshift(Object.assign({}, route));
|
|
119
|
-
config.dependencyRoutes[moduleId] =
|
|
122
|
+
config.dependencyRoutes[moduleId] = configureCDSRoute(moduleId, servicesPaths, route);
|
|
120
123
|
} else {
|
|
121
|
-
config.dependencyRoutes[moduleId] =
|
|
124
|
+
config.dependencyRoutes[moduleId] = configureCDSRoute(moduleId, servicesPaths, config.dependencyRoutes[moduleId]);
|
|
122
125
|
}
|
|
123
126
|
|
|
124
127
|
// add destination for newly configured route
|
|
125
|
-
addDestination(moduleId, process.env.
|
|
128
|
+
addDestination(moduleId, process.env.CDS_PORT || 4004);
|
|
126
129
|
}
|
|
127
130
|
|
|
128
131
|
// create and start the SAP Approuter
|
package/lib/helpers.js
CHANGED
|
@@ -90,13 +90,13 @@ const addDestination = (moduleId, port, mountPath) => {
|
|
|
90
90
|
};
|
|
91
91
|
|
|
92
92
|
/**
|
|
93
|
-
* Configures the route for a given
|
|
93
|
+
* Configures the route for a given CDS module.
|
|
94
94
|
* @param {String} moduleId - the id of the module that the route should be configured for.
|
|
95
|
-
* @param {String[]}
|
|
95
|
+
* @param {String[]} servicesPaths - an array of service paths that the CDS module serves.
|
|
96
96
|
* @param {Object} route - the route that is to be configured.
|
|
97
97
|
* @returns {Object} the configured route.
|
|
98
98
|
*/
|
|
99
|
-
const
|
|
99
|
+
const configureCDSRoute = (moduleId, servicesPaths, route) => {
|
|
100
100
|
if (!route.source) {
|
|
101
101
|
route.source = servicesPaths
|
|
102
102
|
.map((path) => {
|
|
@@ -135,6 +135,6 @@ module.exports = {
|
|
|
135
135
|
parseConfig,
|
|
136
136
|
applyDependencyConfig,
|
|
137
137
|
addDestination,
|
|
138
|
-
|
|
138
|
+
configureCDSRoute,
|
|
139
139
|
configureUI5Route,
|
|
140
140
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dev-approuter",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "A dev time wrapper for the SAP Application Router that can serve UI5 and
|
|
3
|
+
"version": "0.1.18",
|
|
4
|
+
"description": "A dev time wrapper for the SAP Application Router that can serve UI5 and CDS modules added as dependencies.",
|
|
5
5
|
"author": "Nico Schoenteich <nicolai.schoenteich@sap.com> (https://github.com/nicoschoenteich)",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@sap/approuter": ">=14.3.1",
|
|
14
14
|
"@sap/xsenv": "4.0.0",
|
|
15
|
-
"cds-plugin-ui5": "^0.6.
|
|
15
|
+
"cds-plugin-ui5": "^0.6.9",
|
|
16
16
|
"express": "^4.18.2",
|
|
17
|
-
"ui5-middleware-cap": "^3.1.
|
|
17
|
+
"ui5-middleware-cap": "^3.1.4"
|
|
18
18
|
},
|
|
19
|
-
"gitHead": "
|
|
19
|
+
"gitHead": "7ff4fbf9fa7501c5e2691bb2b92c1ea59a403edf"
|
|
20
20
|
}
|