Initially, while working on applications deployed in the SAP Cloud Foundry, I often came across the term AppRouter. As the name suggests, it’s an application router, but I still had many questions about it. What is an AppRouter? Where can I find it? Why do I need an AppRouter? And, which kind do I use and when? Going through many blogs and working with AppRouters hands-on, I have developed a particular understanding of it. In my blog today, I will take you through my understanding of AppRouters.
So let’s dive in!
What is an SAP AppRouter anyway?
The AppRouter is a Node.js library used as a single entry point for an application running in the Cloud Foundry, SAP BTP. You must have read or heard of it; however, what does this mean?
Let’s say a user is trying to access an application by calling the URL; there are a few things that would happen:
- The request comes to the AppRouter of the application.
- The AppRouter checks if authentication is required (configured in xsapp.json of the application) and sends information like client location, cookies, and requested page details to the browser.
- If authentication is required, the AppRouter redirects to the SAP’s IDP Login page.
- Once the login is successful, the AppRouter redirects to the index.html of the application.
Further on from point no. 2 above, the authentication configuration is maintained in a file called xs-app.json. This file can carry other configurations as well, such as;
- Authentication
- Authorization including scope check
- Logout process and redirection
- Session management of the AppRouter
- Destination to access the API with CSRF protection within the application
- Cache
- CORS configuration
Every Application has its AppRouter. We can either use the application’s AppRouter or set up an independent application router.
What are the Different Types of AppRouters?
Managed AppRouters are when we choose to use an application’s AppRouter, whereas Standalone AppRouters refer to situations where we may decide to set up our own.
Difference between Managed AppRouters and Standalone AppRouters
When to use a Managed AppRouter and a Standalone AppRouter?
It is best practice to use a Managed AppRouter in most scenarios as it has inbuilt integration with most SAP business services. We can use a Standalone AppRouter when we want our application to work across tenants.