Skip to content

Instantly share code, notes, and snippets.

@cschuff
Last active February 19, 2018 10:54
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/84a43ddd85eb298bfdd410a58a9e3714 to your computer and use it in GitHub Desktop.
Save cschuff/84a43ddd85eb298bfdd410a58a9e3714 to your computer and use it in GitHub Desktop.
Minimal Express.js server for local SAPUI5 development. Also works for SAP Web IDE projects. Only framework sources are proxied, no OData supported. 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.15.4",
"http-proxy-middleware": "^0.17.4"
}
}
# install dependencies
npm install --save-dev express http-proxy-middleware
# start server
npm start
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.31';
// const ui5Origin = 'https://openui5.hana.ondemand.com/1.44.31';
// 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
app.listen(8000, function () {

console.log('Express server listening on port 8000');

});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment