Skip to content

Deploy into an SAP system (BSP) ​

If your users already sign in to an SAP® ABAP® system, such as SAP S/4HANA®, the simplest home for a browser-client app is that system itself. You upload the built app as a BSP application (the system's container for static web files), and the system serves it from the same host as its OData services. Every call then goes out with the user's own logon: no proxy, no CORS, no server of your own.

The bspApp() Vite plugin gets your dist/ ready for that upload, as it is.

The plugin ​

ts
// vite.config.ts
import vue from "@vitejs/plugin-vue";
import { bspApp } from "@atscript/odata-client/vite";
import { defineConfig } from "vite";

export default defineConfig({
  plugins: [vue(), bspApp({ app: "zui_my_app" })],
});

app must be exactly the name you upload the app under (in /UI5/UI5_REPOSITORY_LOAD, below). The plugin builds the app's URL from it, so if you rename the app, build it again.

What the plugin does:

  • Sets base to the app's URL in the system: /sap/bc/ui5_ui5/sap/zui_my_app/. A namespaced app (/abc/myapp) lives at /sap/bc/ui5_ui5/abc/myapp/.
  • Writes .Ui5RepositoryBinaryFiles into the root of dist/. The upload reads this file to know which files to store byte for byte; without it, images and fonts break. It lists images (png, jpg, jpeg, gif, webp, avif, ico, svg), fonts (woff2, woff, ttf, otf, eot), pdf, xlsx, zip, mp4 and webm.
  • Fails the build on a file type the upload doesn't know, naming the extension to add: bspApp({ app: "zui_my_app", binary: ["heic"] }). Without this check you'd find out after the upload, from a missing image.

Vite adds the base to the URLs it sees: index.html, CSS url(), imported assets and static src in Vue templates. A path you write as a plain string in code is up to you: start it with import.meta.env.BASE_URL.

Routes go in the hash ​

The system serves only files that exist. It has no fallback to index.html, so a route in the path gives a 404 on reload. Keep routes in the hash:

ts
import { createRouter, createWebHashHistory } from "vue-router";

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes,
});

A route then looks like …/zui_my_app/index.html#/orders.

Service URLs ​

The app and the services share a host, so give the client root-relative service URLs:

ts
const sapClient = new URLSearchParams(location.search).get("sap-client");

const odata = createODataClientFactory({
  services: [
    {
      baseUrl: "/sap/opu/odata/sap/ZMY_SERVICE_SRV",
      query: sapClient ? { "sap-client": sapClient } : {},
      model,
      types: sales,
    },
  ],
});

On a system with several clients, the query line passes the page's ?sap-client=… on to every OData call, so they run in the client the user signed in to. Put ?sap-client=NNN in tile and bookmark URLs too.

Develop against your SAP system ​

In the dev server, the plugin forwards /sap/opu and /sap/public to your system once SAP_HOST is set. Put it into .env.local next to vite.config.ts, with a login:

bash
# .env.local
SAP_HOST=https://my-sap-host
SAP_USER=DEVELOPER
SAP_PASSWORD=your-password

With single sign-on, use a session cookie instead of the user and password:

bash
# .env.local
SAP_HOST=https://my-sap-host
SAP_COOKIE=MYSAPSSO2=…; SAP_SESSIONID_…=…
  • To get the cookie, sign in to the system in your browser, open the devtools' Network tab, pick a request to the system and copy its Cookie request header. When both are set, the cookie wins.
  • Never commit .env.local. Vite's project templates ignore *.local in .gitignore; check that yours does.
  • The dev server serves the app under its base too: http://localhost:<port>/sap/bc/ui5_ui5/sap/zui_my_app/.
  • Need another path of the system? Add it to server.proxy yourself, but never /sap as a whole: it would catch the app's own base.
  • If the system's certificate comes from your company's own CA, point Node at it: NODE_EXTRA_CA_CERTS=/path/to/company-ca.pem.

Upload ​

The upload is the report /UI5/UI5_REPOSITORY_LOAD:

  1. Build the app: vp build (or vite build).
  2. In transaction SE38, run /UI5/UI5_REPOSITORY_LOAD. Enter the app name (ZUI_MY_APP, the same as app), choose Upload and run it.
  3. Select the dist/ folder, the one with index.html in it.
  4. Enter the package, a description and a transport request, set the code page to UTF-8, and confirm.

The upload mirrors the folder: files missing from dist/ are deleted in the system, so always upload a fresh build. The app moves on to other systems with its transport request (object R3TR WAPA ZUI_MY_APP).

After an upload, hard-reload the page (Ctrl+Shift+R, or Cmd+Shift+R on a Mac): your browser may still hold the old index.html.

Open it ​

The app is at https://my-sap-host/sap/bc/ui5_ui5/sap/zui_my_app/index.html (add ?sap-client=100 before any # when the system has several clients); for the SAP Fiori® launchpad, create a tile for a URL-type app that points there.

When the session ends ​

When the user's SAP logon has expired, the system answers the next call in one of three ways, depending on how it's set up:

  • 401, which reaches your code as a ClientError with status 401;
  • its logon page, with status 200. The browser client reports that as a ClientError 401 too, with code UNEXPECTED_CONTENT;
  • with single sign-on (SAML), a redirect to the sign-in server on another host. fetch can't follow it, so the client reports a TransportError.

The fix is the same every time: reload the page. The system's normal sign-in runs, and because the route is in the hash, the user lands back where they were. Anything typed and not saved is lost, so ask first. Call this where your app handles errors from calls (your catch blocks, the start error of connect()):

ts
import { ClientError, TransportError } from "@atscript/db-client";

export function reloadIfSignedOut(error: unknown): void {
  const signedOut =
    (error instanceof ClientError && error.status === 401) ||
    (error instanceof TransportError && !error.aborted);
  if (signedOut && confirm("Your session has ended. Reload to sign in again?")) location.reload();
}

A TransportError can also mean the network dropped; asking first keeps a reload then harmless.

Troubleshooting ​

You seeWhyFix
A blank page, with 404s for /sap/bc/ui5_ui5/sap/<other-name>/assets/…The app was uploaded under another name than appBuild with app set to the uploaded name, and upload again
An image is missingIts path is a plain string in code, so Vite didn't add the baseStart the path with import.meta.env.BASE_URL
A reload or a link gives 404The route is in the path, not the hashUse createWebHashHistory (Routes go in the hash)
In dev, a logon page or 401 from /sap/opu/…The password or cookie in .env.local is wrong or has expiredUpdate .env.local and restart the dev server

See also ​

SAP, SAP S/4HANA, SAP Fiori, SAPUI5, SAP BTP and other SAP products and services mentioned herein, as well as their respective logos, are trademarks or registered trademarks of SAP SE (or an SAP affiliate company) in Germany and other countries. Atscript OData is an independent open-source project and is not affiliated with, sponsored or endorsed by SAP SE.
Released under the MIT License.