I am having a problem running an SAPUI5 application locally with Visual Studio Code. I am serving the webapp files with a static files server run by Grunt at localhost:8080 The problem is reaching the backend OData services. The first problem which was a CORS error I have solved with using a reverse proxy which is run by NodeJS.
This is the code of the reverse proxy:
var express = require('express');
var app = express();
const https = require('https');
var httpProxy = require('http-proxy');
var apiProxy = httpProxy.createProxyServer();
var backendHost = "YYY-XXX.dispatcher.hana.ondemand.com";
var frontend = 'http://localhost:8080';
var fs = require('fs');
app.all("/sap/opu/*", function (req, res) {
console.log("HOST:" + req.hostname + " URL: " + req.url);
apiProxy.web(req, res, {
changeOrigin: true,
hostRewrite: false,
followRedirects: true,
autoRewrite: true,
protocolRewrite: true,
preserveHeaderKeyCase: true,
xfwd:true,
target: {
hostname: backendHost,
port: 443,
protocol: 'https:',
host: backendHost,
agent: https.globalAgent,
pfx: fs.readFileSync('F:\\Cert.pfx'),
passphrase: 'XXX',
}
});
});
app.all("*", function (req, res) {
apiProxy.web(req, res, { target: frontend });
});
var server = require('http').createServer(app);
server.listen(3000);
The code is running fine. When I enter in the browser localhost:3000 I get the web app files, but I can see that requests made by the webapp towards the the SAP backend ("YYY-XXX.dispatcher.hana.ondemand.com") yields the following html response:
"Note: Your browser does not support JavaScript or it is turned off. Press the button to proceed. Continue"
One more thing: Is there any test environment for the SAPUI5 app on SAP cloud platform? I can only see the "live" version which is the production code. Is there any staging environment?
I would appreciate any help because using Web IDE is not an option for me. Thanks in advance!