Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 同一端点上http和WebSocket的proxy.conf文件_Node.js_Angular_Npm - Fatal编程技术网

Node.js 同一端点上http和WebSocket的proxy.conf文件

Node.js 同一端点上http和WebSocket的proxy.conf文件,node.js,angular,npm,Node.js,Angular,Npm,我有一个工作的开发环境,在这个环境中,我使用proxy.conf.json文件将http请求代理到在我的后端/笔记本电脑上运行的django服务器: { "/graphql": { "target": "https://localhost:443/graphql", "secure": false, "changeOrigin": true,

我有一个工作的开发环境,在这个环境中,我使用proxy.conf.json文件将http请求代理到在我的后端/笔记本电脑上运行的django服务器:

{
    "/graphql": {
        "target": "https://localhost:443/graphql",
        "secure": false,
        "changeOrigin": true,
        "logLevel": "debug"
    }
}
我使用这个代理文件(如上)运行npm服务器

现在我需要在同一个端点(/graphql)上设置WebSocket,我不确定如何为同一个端点定义两个不同的规则——根据请求的协议,https和ws各定义一个规则


我想我可能需要改用javascript来实现这一点,但不确定如何继续。欢迎提供任何帮助/指针。

结果表明,我所需要的只是在代理文件中指定
“ws”:true
。我担心我需要确定协议(ws-vs-http),然后根据传入的请求有条件地(a)更改目标协议(ws-vs-http)和(b)将websocket的ws选项更改为true

但事实证明,只要指定
“ws”:true
,http连接就会升级到ws,因此不需要其他任何东西。我还需要在目标中删除端点。对我有用的最后一个文件是:

{
    "/graphql": {
        "target": "https://localhost:443",
        "secure": false,
        "changeOrigin": true,
        "logLevel": "debug",
        "ws": true
    }
}
因此不需要javascript