路径上带有nodejs的socket.iohttp:// localhost:3000 / path

问题描述

我有一个可以监听localhost:3000

的应用程序设置

但是我的要求有些不同,因为我必须使用路径http;//localhost:3000/path。当我更新server.js文件时,它可以运行curl localhost:3000/path,并且我从index.html得到响应。但是无法获得socket.io

的回应

类似于http;//localhost:3000/path/socket.io/?无效,但http;//localhost:3000/socket.io/?有效。尽管我已经在 index.html 中定义了这一点:

if (event == 'continue') {
                socket = io.connect('',{
                    path : "/path/socket.io",query: "chatID=" + window.name +
                        "&Authentication=" + sessionStorage.getItem('token') + "&template=" + template + "&AdditionalData=" + additionalD
                });
            }
            else {
                socket = io.connect('',query: "chatID=" + window.name +
                        "&Authentication=" + sessionStorage.getItem('Authentication') + "&template=" + template + "&AdditionalData=" + additionalD
                });
            }

解决方法

我通过在server.js中添加var io = path{"/app"}来解决了这个问题