Skip to content

Instantly share code, notes, and snippets.

@cschuff

cschuff/package.json

Last active Jun 19, 2018
Embed
What would you like to do?
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
You can’t perform that action at this time.