如何将httpServer响应委派为快速服务器发布响应

时间:2013-09-10 07:01:17

标签: node.js express sap httpserver netweaver

在我的场景中,我的框架包括SAP Business Data(以json格式),nodejs中间层和浏览器前端。我需要创建一个将SAP业务拉到前端的实时应用程序,进行编辑并将编辑后的数据发送回sap服务器。

现在,要实现这一点,我使用expresshttp模块。我使用express(post request)连接到sap后端并以json格式检索数据,并嵌入了一个http web服务器,它将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(前端 - >前端)

我希望response.send(jsonp)发送修改后的json文件,但是它返回[]即它的初始值,而且我得到修改过的json,下次在sap中重启服务器程序。
请帮助!!

0 个答案:

没有答案
相关问题