gpt4 book ai didi

node.js - Sailsjs 错误 : Cannot write to response more than once at onlyAllowOneResponse

转载 作者:搜寻专家 更新时间:2023-11-01 00:41:14 35 4
gpt4 key购买 nike

Sails Controller 为 ajax 请求返回正确的响应,但是当通过 io.socket 调用时它不起作用。

套接字请求:

io.socket.request({ method: 'get', url: '/example-service/', params: {}, headers:{}}, function(body, JWR){ console.log(JWR); })

异常(exception):

Error: Cannot write to response more than once\n    at onlyAllowOneResponse
node_modules/sails/lib/router/res.js:375:11
at MockServerResponse.send_shim [as send]
node_modules/sails/lib/router/res.js:192:7)

浏览器上的套接字响应:

JWR {body: "Not implemented in core yet", headers: Object, statusCode: 501, error: "Not implemented in core yet"}

根据 sailsjs 文档请求/响应将自动处理 websockets。

我是不是漏掉了什么。对于套接字请求,我是否需要以不同的方式发送响应?

最佳答案

异常是因为我使用的是 res.render,如本文档中所述,sails 在 websockets 中不支持它:

http://sailsjs.org/documentation/reference/response-res

通过替换修复了这个问题

res.render 

sails.hooks.views.render

关于node.js - Sailsjs 错误 : Cannot write to response more than once at onlyAllowOneResponse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33871560/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com