Skip to content

Commit

Permalink
feat(cap): cleanup scripts and localrouter
Browse files Browse the repository at this point in the history
  • Loading branch information
longieirl committed Sep 29, 2023
1 parent 42407c6 commit 715bb9e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
24 changes: 21 additions & 3 deletions cap/cap-fiori-hybrid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,33 @@ __At this point, you have deployed your application to CF, if you run the CAP pr

- Bind to the XSUAA service `cds bind -2 managedAppCAPProject-xsuaa-service --kind xsuaa`
- Bind to the HANA HDI service `cds bind -2 managedAppCAPProject-db`
- Spin up your CAP project in hybrid mode `npm run watch:hyrbid`
- Spin up your CAP project in hybrid mode `npm run watch:hybrid` but don't click the `Open in a New Tab` prompt since this is not authenticating the user with XSUAA security
- The console output will show HANA connectivity;

__To imitate a `production-near` environment, you need to route the HTTP requests to your SAP BTP services. The `localrouter` will fetch a valid token from the XSUAA instance and attach it to every subsequent request.__
```
[cds] - connect using bindings from: { registry: '~/.cds-services.json' }
[cds] - connect to db > hana {
```

__To imitate a `production-near` environment, you need to route the HTTP requests to your SAP BTP XSUAA and HANA services. The `localrouter` will fetch a valid token from the XSUAA instance and attach it to every subsequent request.__

- Install the local approuter `npm run install:localrouter`
- Spin up the local approuter `npm run start:router`
- Spin up the local approuter `cds bind --exec -- npm start --prefix localrouter`
- Open your CAP Project using the `localrouter:5001` endpoint, `View` -> `Ports: Preview` -> select port 5001
- Open the new browser tab and select your Fiori UI application

## Gotchas

### Forbidden

You have tried to load your Fiori UI application on port 5001 but get the following error message;
```
Application could not be started due to technical issues.
Forbidden
```

Please ensure you have assigned your email address to the `capuser` role in your SAP BTP cockpit under security, follow [this guide](https://cap.cloud.sap/docs/node.js/authentication#auth-in-cockpit) for steps.

## Get Support

In case you've a question, find a bug, or otherwise need support, use the [SAP Community](https://answers.sap.com/tags/9f13aee1-834c-4105-8e43-ee442775e5ce) to get more visibility.
Expand Down
19 changes: 11 additions & 8 deletions cap/cap-fiori-hybrid/localrouter/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"name": "approuter",
"scripts": {
"start": "node node_modules/@sap/approuter/approuter.js"
},
"dependencies": {
"@sap/approuter": "^14"
}
}
"name": "approuter",
"dependencies": {
"@sap/approuter": "^14.0.0"
},
"engines": {
"node": "^18.0.0"
},
"scripts": {
"start": "node node_modules/@sap/approuter/approuter.js"
}
}
16 changes: 9 additions & 7 deletions cap/cap-fiori-hybrid/localrouter/xs-app.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"routes": [
{
"source": "^/(.*)",
"destination": "cap-catalog-api"
}
]
}
"routes": [
{
"source": "^/(.*)$",
"target": "$1",
"destination": "srv_api",
"csrfProtection": true
}
]
}
1 change: 0 additions & 1 deletion cap/cap-fiori-hybrid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
},
"scripts": {
"start": "cds run",
"start:router": "cds bind --exec -- npm start --prefix localrouter",
"undeploy": "cf undeploy managedAppCAPProject --delete-services --delete-service-keys --delete-service-brokers",
"build": "rimraf resources mta_archives && mbt build --mtar archive",
"deploy": "cf deploy mta_archives/archive.mtar --retries 1",
Expand Down

0 comments on commit 715bb9e

Please sign in to comment.