Skip to content

Commit

Permalink
Merge pull request SAP-samples#428 from SAP-samples/multi-tenat-sample
Browse files Browse the repository at this point in the history
multi tenant sample
  • Loading branch information
FrankEssenberger authored Oct 6, 2022
2 parents 0f56b64 + 4e41a85 commit cbfbfef
Show file tree
Hide file tree
Showing 22 changed files with 4,401 additions and 9 deletions.
3 changes: 0 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions samples/cf-multi-tenant-application/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "http://json.schemastore.org/prettierrc",
"singleQuote": true,
"filepath": "*.ts",
"trailingComma": "none",
"arrowParens": "avoid"
}
55 changes: 55 additions & 0 deletions samples/cf-multi-tenant-application/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# SAP Cloud SDK for JavaScript Multi-Tenant Sample Application

## Description

The code sample in this directory is a reference for the [multi-tenant application tutorial](https://sap.github.io/cloud-sdk/docs/js/tutorials/multi-tenant-application).
You need to make adjustments to the code before deployment.
The terms you need to replace are given in all caps and start with _`YOUR_`_ e.g. _`YOUR_REGION`_.

Also, note that the samples here are intended as a didactic example and are not necessarily a best practice.
The repositories' structure is as follows:

- [./multi-tenant-app](./multi-tenant-app) - Contains the code of the multi-tenant application.
It contains a simple service endpoint and logic to be executed on subscription and unsubscription.
- [./approuter](./approuter) - Contains the approuter necessary to attach JSON web tokens to the application.
- [./service-config](./service-config) - Directory configurations for service instances.

## Requirements

The minimal requirements are:

- A terminal to execute commands
- A recent version of node and npm installed e.g. node 14 and npm 6
- A recent installation of the [Cloud Foundry command line interface](https://developers.sap.com/tutorials/cp-cf-download-cli.html)
- An IDE or a text editor of your choice
- Access to a [SAP Business Technology Platform](https://www.sap.com/products/business-technology-platform.html) account
- Entitlement to use resources like service instance creation and application processing units
- Permission to deploy applications and create service instances

## Download and Deployment

To download the application run:

```
git clone \
--depth 1 \
--filter=blob:none \
--sparse \
https://github.com/SAP-samples/cloud-sdk-js.git \
;
cd cloud-sdk-js
git sparse-checkout set samples/cf-multi-tenant-application
```

### Create Services on SAP BTP Cloud Foundry

Before you can deploy the application, you have to create a `destination` and `xsuaa` service instance.
Their name should match the one that is used in the application `manifest.yml`, in this case:

- `destination`
- `xsuaa`

### Deploy the Application to SAP BTP Cloud Foundry

Run `cf push` in the application directory to deploy the application.
Please follow the steps described in the [multi-tenant application tutorial](https://sap.github.io/cloud-sdk/docs/js/tutorials/multi-tenant-application) for the deployment steps of all components.
17 changes: 17 additions & 0 deletions samples/cf-multi-tenant-application/approuter/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
applications:
- name: approuter
routes:
- route: 'route-prefix-YOUR_SUBDOMAIN.cfapps.YOUR_REGION.hana.ondemand.com'
path: .
memory: 128M
buildpacks:
- nodejs_buildpack
env:
TENANT_HOST_PATTERN: 'route-prefix-(.*).cfapps.YOUR_REGION.hana.ondemand.com'
destinations: >
[
{"name":"multi-tenant-app","url":"https://multi-tenant-app.cfapps.YOUR_REGION.hana.ondemand.com","forwardAuthToken":true}
]
services:
- xsuaa
- destination
9 changes: 9 additions & 0 deletions samples/cf-multi-tenant-application/approuter/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "approuter",
"dependencies": {
"@sap/approuter": "latest"
},
"scripts": {
"start": "node node_modules/@sap/approuter/approuter.js"
}
}
10 changes: 10 additions & 0 deletions samples/cf-multi-tenant-application/approuter/xs-app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"welcomeFile": "index.html",
"routes": [
{
"source": "(.*)",
"target": "/$1",
"destination": "multi-tenant-app"
}
]
}
11 changes: 11 additions & 0 deletions samples/cf-multi-tenant-application/multi-tenant-app/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
applications:
- name: multi-tenant-app
path: .
memory: 256M
buildpacks:
- nodejs_buildpack
services:
- destination
- xsuaa
routes:
- route: 'multi-tenant-app.cfapps.YOUR_REGION.hana.ondemand.com'
Loading

0 comments on commit cbfbfef

Please sign in to comment.