Skip to content

Instantly share code, notes, and snippets.

@cschuff
Last active June 19, 2018 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cschuff/6f23b61622b41fdaa3c01623e530b845 to your computer and use it in GitHub Desktop.
Save cschuff/6f23b61622b41fdaa3c01623e530b845 to your computer and use it in GitHub Desktop.
Minimal Express.js server for local SAPUI5 development. Proxies framework sources as well as backend services with no project source adjustments! Also works for SAP Web IDE projects. Run with '$ npm start'.
{
"name": "ui5-experts-servergist",
"version": "1.0.0",
"description": "",
"main": "server.js",
"author": {
"name": "Christian Schuff",
"email": "christian.schuff@ui5experts.com",
"url": "http://www.ui5experts.com"
},
"license": "MIT",
"devDependencies": {
"express": "^4.16.3",
"proxy-middleware": "^0.15.0"
}
}
const express = require('express');
const url = require('url');
const proxy = require('proxy-middleware');
const app = express();
const ui5Origin = 'https://sapui5.hana.ondemand.com/1.44.37';
// const ui5Origin = 'https://openui5.hana.ondemand.com/1.44.37';
// const ui5Origin = 'https://[BACKEND_HOST]:[BACKEND_PORT]/sap/public/bc/ui5_ui5/1.44';
const backend = 'https://[BACKEND_HOST]:[BACKEND_PORT]';
// statically serve webapp folder, use test.html as index (as used in SAP Web IDE templates)
app.use(express.static('webapp', { index: 'test.html' }));
// proxy resources and test-resources from remote location
let proxyOptions = url.parse(`${ui5Origin}/resources`);
proxyOptions.cookieRewrite = true;
app.use('/resources', proxy(proxyOptions));
proxyOptions = url.parse(`${ui5Origin}/test-resources`);
proxyOptions.cookieRewrite = true;
app.use('/test-resources', proxy(proxyOptions));
// proxy backend
proxyOptions = url.parse(`${backend}/sap`);
proxyOptions.cookieRewrite = true;
app.use('/sap', proxy(proxyOptions));
// start server
const port = 8000;
const server = app.listen(port, () => console.log(`Express server listening on port ${port}`));
module.exports = server;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment