先看异常
Failed to connect socket (possibly due to failed `beforeConnect` on server) Error: Invalid namespace
项目是前后端分离
我使用的是sails框架,前端页面前端使用sails.io.js
sails使用pm2起了多个实例,然后使用nginx做反向代理,配置如下
upstream test-node {
server 127.0.0.1:31011;
}
server {
listen 80;
server_name xxx.yyy.com;
charset utf-8;
location /proj/ {
proxy_pass http://test-node/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
到了前端页面,代码如下
import sailsIO from 'sails.io.js'
import socketIOClient from 'socket.io-client'
const io = sailsIO(socketIOClient)
io.sails.url = 'http://xxx.yyy.com/proj'
io.sails.path = '/proj/socket.io/'
结果报了上述异常,请问有人知道怎么解决么。是不是我的写法有问题
使用http://xxx.yyy.com/proj去访问sails的所有接口都是正常的。