This section describes how you can set up your own application router.
-
cf CLI is installed locally, see Download and Install the Cloud Foundry Command Line Interface.
-
Node.js is installed and configured locally, see npm documentation.
-
The SAP npm registry, which contains the Node.js package for the application router, is configured:
npm config set @sap:registry https://registry.npmjs.org
The application router is configured in the xs-app.json
file. The package.json
file contains the start command for the application router and a list of package dependencies.
-
Create the application resource-file structure.
For example,
/path/<myAppName>/
-
Create a subfolder for the static Web resources module.
The subfolder for the Web-resources module must be located in the application root folder, for example,
/path/<myAppName>/web
.The Web-resource module uses
@sap/approuter
as a dependency; the Web-resources module also contains the configuration and static resources for the application. -
Create the subfolder for the application's static resources.
Static resources can, for example, include the following file and components:
index.html
, style sheets (.css
files), images and icons. Typically, static resouces for a Web application are placed in a subfolder of the Web module, for example,/path/<myAppName>/web/resources
. -
Create the application-router configuration file.
The application router configuration file
xs-app.json
must be located in the application's Web-resources folder, for example,/path/<MyAppName>/web
.<myAppName> |- web/ # Application descriptors | |- xs-app.json # Application routes configuration | |- package.json # Application router details/dependencies | \- resources/
-
Define details of the application's routes, destinations, and security scopes.
The contents of the
xs-app.json
file must use the required JSON syntax. For more information, see Routing Configuration File.-
Create the required destinations configuration.
/path/<myAppName>/web/xs-app.json
.{ "welcomeFile": "index.html", "routes": [ { "source": "/sap/ui5/1(.*)", "target": "$1", "localDir": "sapui5" }, { "source": "/rest/addressbook/testdataDestructor", "destination": "backend", "scope": "node-hello-world.Delete" }, { "source": "/rest/.*", "destination": "backend" }, { "source": "^/(.*)", "localDir": "resources" } ] }
-
Add the routes (destinations) for the specific application (for example,
node-hello-world
) to theenv
section of the application’s deployment manifest (manifest.yml
).Every route configuration that forwards requests to a micro service has property destination. The destination is a name that refers to the same name in the destinations configuration. The destinations configuration is specified in an environment variable passed to the approuter application.
<myAppName>/manifest.yml
- name: node-hello-world routes: - route: myHost-node-hello-world.xsapps.acme.ondemand.com memory: 100M path: web env: destinations: > [ { "name":"backend", "url":"http://myHost-node-hello-world-backend.xsapps.acme.ondemand.com", "forwardAuthToken": true } ]
-
-
Add a package descriptor (
package.json
) for the application router to the root folder of your application's Web resources module (web/
) and executenpm install
to download the approuter npm module from the SAP npm registry.The package descriptor describes the prerequisites and dependencies that apply to the application router and starts the application router, too.
<myAppName> |- web/ # Application descriptors | |- xs-app.json # Application routes configuration | |- package.json # Application router details/dependencies | \- resources/
The basic
package.json
file for your Web-resources module (web/
) should look similar to the following example:{ "name": "node-hello-world-approuter", "dependencies": { "@sap/approuter": "5.1.0" }, "scripts": { "start": "node node_modules/@sap/approuter/approuter.js" } }
The start script (for example,
approuter.js
) is mandatory; the start script is executed after application deployment.
Related Information