node-red等待http-response的异步查询

时间:2017-10-01 11:38:07

标签: node.js node-red

我使用node-red完成REST端点,它执行一些异步任务,例如对数据库进行odbc-query。

当我对http响应进行查询时。它只是挂在浏览器上。 看起来我需要转发req和res对象到http响应。但我是怎么做到的?

以下是流程:

[{"id":"a35e6901.509a1","type":"http in","z":"ec714e97.d73b58","name":"","url":"/get","method":"get","upload":false,"swaggerDoc":"","x":287.8571472167969,"y":1660.357177734375,"wires":[["7c116e0a.f8d67"]]},{"id":"98e22918.79bc4","type":"sqldbs","z":"ec714e97.d73b58","mydb":"8df7f8b0.bd44c","querytype":"select","name":"","x":723.5714111328125,"y":1644.6428833007812,"wires":[["de837ef9.5c1cf8"]]},{"id":"7c116e0a.f8d67","type":"function","z":"ec714e97.d73b58","name":"","func":"msq.topic = \"Select * from User\"\nreturn msg;","outputs":1,"noerr":0,"x":469.28570556640625,"y":1613.9286499023438,"wires":[["98e22918.79bc4"]]},{"id":"de837ef9.5c1cf8","type":"http response","z":"ec714e97.d73b58","name":"","statusCode":"","headers":{},"x":922.1428833007812,"y":1677.8570861816406,"wires":[]},{"id":"8df7f8b0.bd44c","type":"sqldbsdatabase","z":"","host":"127.0.0.1","port":"1433","db":"test","dialect":"mysql"}]

1 个答案:

答案 0 :(得分:1)

您需要确保它是从http-in节点一直流向http-out节点的相同消息对象。

此消息对象将包含msg.reqmsg.res字段,msg.res节点将使用http-out字段将响应发送回浏览器。< / p>

任何接受输入然后转发的节点都应该保留这些字段,而不仅仅是为输出创建一个新对象。所有内置节点都正确执行此操作,并且所有已发布的第三方节点也应如此。如果你发现一个不遵循这种模式,你应该提出维护者的错误。

您的流程看起来不错,但我从未使用过您拥有的数据库节点,因此无法对其进行评论。