我正在尝试连接到Sails v1.0上的套接字,但是它不起作用。这是我做的。 首先,我使用“ sails new test”命令创建新项目。 然后我用“ sails lift”命令运行。 然后我用以下内容(代码)创建一个index.html文件:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://localhost:1337/dependencies/sails.io.js"></script>
</head>
<body>
</body>
</html>
,然后在浏览器中打开该index.html。然后我得到了错误(结果):
The socket was unable to connect.
sails.io.js:441 The server may be offline, or the
sails.io.js:441 socket may have failed authorization
sails.io.js:441 based on its origin or other factors.
sails.io.js:441 You may want to check the values of
sails.io.js:441 `sails.config.sockets.onlyAllowOrigins`
sails.io.js:441 or (more rarely) `sails.config.sockets.beforeConnect`
sails.io.js:441 in your app.
sails.io.js:441 More info: https://sailsjs.com/config/sockets
sails.io.js:441 For help: https://sailsjs.com/support
sails.io.js:441
sails.io.js:441 Technical details:
sails.io.js:441 Error: websocket error
at d.onError (sails.io.js:17)
at WebSocket.ws.onerror (sails.io.js:17)
sails.io.js:441 ====================================
然后我打开文件sails.config.sockets并进行设置 onlyAllowOrigins:['http://localhost','http://192.168.1.158','http://127.0.0.1'] 帆再次升起。但是问题仍然存在。我尝试了所有我能想到的价值观,但没有一个起作用。我在哪里错了?