Skip to content

Instantly share code, notes, and snippets.

@jasper07
Last active June 2, 2019 12:19
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jasper07/8577268 to your computer and use it in GitHub Desktop.
Simple Node reverse proxy for UI5 development
var express = require('express'),
httpProxy = require('http-proxy'),
proxy = new httpProxy.createProxyServer();
var routing = {
'sapui5': {
target: 'http://localhost:8001' //sdk
},
'apps': {
target: 'http://localhost:8002' //applications
},
'sap': { // sap -> root icf eg /sap/opu/odata etc
target: 'https://sapes1.sapdevcenter.com/'
}
// 'sap': { //https
// target: {
// host: < server > ,
// port: < port > ,
// https: true,
// rejectUnauthorized: false, //continue on unsigned certificates
// },
// }
};
var allowCrossDomain = function(req, res) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Credentials', 'true');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'X-Requested-With, Accept, Origin, Referer, User-Agent, Content-Type, Authorization, X-Mindflash-SessionID');
// intercept OPTIONS method
if ('OPTIONS' === req.method) {
res.header(200);
} else {
var dirname = req.url.replace(/^\/([^\/]*).*$/, '$1'); //get root directory name eg sdk, app, sap
console.log(req.method + ': ' + routing[dirname].target + req.url);
proxy.web(req, res, routing[dirname]);
}
};
var app = express();
app.configure(function() {
app.use(allowCrossDomain);
}).listen(8000);
@timothymuchena
Copy link

Hi.

How do I implement this with node js. I have a folder structure and in that folder is a server.js file. Do i create a proxy.js in the same folder containing the server.js file? What other steps are required to have this working?

Thank you

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