Warm tip: This article is reproduced from serverfault.com, please click

Hosting a UI5 webapp with express

发布于 2020-11-25 18:55:50

There is a UI5 sample app:

https://github.com/SAP/openui5-sample-app and it can be easily hosted with:

UI5 serve -o index.html or with npm run serve-dist after building

But, how do i host it with express?

Questioner
David
Viewed
0
Martin Böschen 2020-11-29 03:34:19

Strictly speaking, you ARE using an express app, when using the UI5 server via the command UI5 serve -o index.html. This code initializes the express app.

If you want to do it by your own, you can use the following code in an app.js file and start it via node app.js:

'use strict';

const express = require('express');
const app = express();

app.use(express.static('webapp'));

app.listen(8080, () => {*
    console.log(`App listening at http://localhost:8080`)
})

This app basically does nothing else than serving files from the webapp folder. One disadvantage over using the UI5 Server is that you need to provide the resources in some way. You can reference the ui5 resources from a Content Delivery Network if you change the bootstrap script in you index.html file as show here:

<script id="sap-ui-bootstrap"
    src="https://openui5.hana.ondemand.com/1.84.0/resources/sap-ui-core.js"
    data-sap-ui-libs="sap.m"
    ...

This would serve the example app from your self-coded UI5 app.