在我的场景中,我的框架由 SAP 业务数据(json 格式)、nodejs 中间层和浏览器前端组成。我需要创建一个实时应用程序,将 SAP 业务拉到前端,进行编辑并将编辑后的数据发送回 sap 服务器。
现在,为了实现这一点,我正在使用express和http模块。我正在使用 express(post request) 连接到 sap 后端并以 json 格式检索数据,并嵌入了一个 http webserver,它将 json 数据作为前端使用的 url 托管。
当用户在前端进行编辑时,我能够从 httpServer 实例响应中获取响应,但是在我可以将浏览器的 httpResponse 委托为快速发布响应之前,外部快速发布响应正在返回。
我包含了一部分代码或插图:
app.post('/publish', auth, function (request, response) {
json = JSON.stringify(request.body);
//io.sockets.emit("SAP_Event", request.body);
http.createServer(function(req,res){
//var f = 'index.html';
if(res.url == '/favicon.ico'){ // To handle non-existant favicon request by the http client
res.writeHead(404,{'Content-Type' : 'text/plain'});
res.end('Couldn\'t locate the required resource');
return;
}
var headers = { 'Content-type' : 'application/json' ,
'Access-Control-Allow-Origin' : '*',
'Access-Control-Allow-Headers' : 'X-Requested-With,GET,Content-Type'};
res.writeHead(200,headers);
res.end(json);
//***********************************
if(req.method === "POST") {
var data = "";
req.on("data", function(chunk) {
data += chunk;
});
req.on("end", function() {
jsonp = qs.parse(data);
});
}
//***********************************
}).listen(8080);
response.send(jsonp);
});
注意: json 是拉取的 json(sap -> frontend) jsonp 是推送的(修改的) json (frontend -> frontend)
我希望 response.send(jsonp) 发送修改后的 json 文件,但它返回 [] 即它的初始值,而且我正在获取修改后的 json,下次在 sap 中重新启动服务器程序。
请帮忙!!