1

我正在尝试使用node-red作为前端来与我正在构建的 REST API 交互。我的 API 使用 https,但在我的本地服务器上,证书没有完美设置,当我尝试使用“http 请求”节点时出现错误:

 UNABLE_TO_VERIFY_LEAF_SIGNATURE

有没有办法将 node-red 配置得不那么严格并允许 SSL 协议错误并继续处理 http 请求?有没有人创建了他们自己版本的“http 请求”节点,它比默认的更严格?

(在 Google Chome 浏览器中,我有一个绿色挂锁,所以 SSL 几乎是正确的,node-red 非常挑剔)


要运行 node-red,我使用 docker:

docker run -dp 1880:1880 -v ~/.node-red:/root/.node-red --name node-red cpswan/node-red

这是我的节点红色项目源代码:

[{"id":"e246fcb9.1db9","type":"inject","name":"Trigger user/me","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":200,"y":140,"z":"e7bac913.184538","wires":[["f9d78108.06288"]]},{"id":"96b8b92c.694748","type":"http request","name":"user/me","method":"GET","ret":"obj","url":"https://local.supertasker.com/api/user/me","x":711,"y":141,"z":"e7bac913.184538","wires":[["5150419b.aeafc"]]},{"id":"5150419b.aeafc","type":"debug","name":"","active":true,"console":"false","complete":"false","x":906,"y":140,"z":"e7bac913.184538","wires":[]},{"id":"f9d78108.06288","type":"function","name":"Add 'Accept:application/json' header","func":"\nmsg.headers = {\n    'Accept':'application/json'\n};\n\n// Return the message so it can be sent on\nreturn msg;","outputs":1,"valid":true,"x":464,"y":140,"z":"e7bac913.184538","wires":[["96b8b92c.694748"]]}]
4

4 回答 4

5

目前,node-red 没有直接公开执行此操作的方法,但您可以设置NODE_TLS_REJECT_UNAUTHORIZED环境变量以在 node.js 级别禁用它:

例如:

NODE_TLS_REJECT_UNAUTHORIZED=0 node red.js
于 2015-05-01T09:05:23.650 回答
1

settings.js在文件中添加以下代码。module.exports行前

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

如果要查找文件位置,请运行 node-red 它,也会显示文件位置。

于 2020-09-04T10:54:48.553 回答
0

In case it helps anyone, here is how you can try node-red using Docker without HTTPS errors using the ENV var that @knolleary brought to light (NODE_TLS_REJECT_UNAUTHORIZED=0):

Create a Dockerfile with this inside:

FROM node:0.10
RUN npm install -g node-red
EXPOSE 1880
ENV NODE_TLS_REJECT_UNAUTHORIZED=0
CMD ["/usr/local/bin/node-red"]

Build it:

docker build -t="yourname/node-red" .

Run it:

docker run -dp 1880:1880 -v ~/.node-red:/root/.node-red --name node-red yourname/node-red

Browse to: http://127.0.0.1:1880/

If you need the node-red app to access services running on the host, you can add the name of the service to /etc/hosts of the node-red container referencing the docker gateway IP:

docker exec node-red sh -c "echo '172.17.42.1\tmy.local.service.com\n' >> /etc/hosts"

After this, a node-red "http request" node can use my.local.service.com in the url.

于 2015-05-01T09:40:38.197 回答
0

我在 ubuntu 20.04 LTS 上使用snapd安装了node-red

如果有人在 ubuntu 上使用此工具遇到同样的问题,请查看:

/etc/systemd/system/snap.node-red.node-red.service

节点红服务定义

你会发现应用程序正在使用/etc/environment文件来设置环境变量

更新

改为EnvironmentFile=..._Environment="NODE_TLS_REJECT_UNAUTHORIZED=0"

之后,使用以下命令重新启动 systemd 和 snap.node-red 服务:

sudo systemctl daemon-reload && service snap.node-red.node-red restart

确保服务正在运行:

sudo service snap.node-red.node-red status

节点红服务

请求应该正常通过 节点红色 HTTPs 请求工作示例

于 2021-02-15T11:47:28.323 回答