0

我在使用 Visual Studio Code 在本地运行 SAPUI5 应用程序时遇到问题。我正在使用 Grunt 在 localhost:8080 运行的静态文件服务器为 webapp 文件提供服务 问题是到达后端 OData 服务。第一个问题是 CORS 错误,我使用 NodeJS 运行的反向代理解决了这个问题。

这是反向代理的代码:

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);

代码运行良好。当我在浏览器中输入 localhost:3000 时,我得到了 Web 应用程序文件,但我可以看到 Web 应用程序向 SAP 后端(“YYY-XXX.dispatcher.hana.ondemand.com”)发出的请求会产生以下 html回复:

“注意:您的浏览器不支持 JavaScript 或已关闭。按按钮继续。继续”

还有一件事:SAP云平台上的SAPUI5应用有测试环境吗?我只能看到作为生产代码的“实时”版本。有舞台环境吗?

我会很感激任何帮助,因为使用 Web IDE 对我来说不是一个选项。提前致谢!

4

0 回答 0