Last active
February 19, 2018 10:54
-
-
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'.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install dependencies | |
npm install --save-dev express http-proxy-middleware | |
# start server | |
npm start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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