我如何让socket.io运行一个子目录 [英] How do I get socket.io running for a subdirectory
本文介绍了我如何让socket.io运行一个子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在运行一个代理,该代理仅在我的node.js服务器上找到/mysubdir
所在的路径
如何为这种情况配置socket.io?
I've got a proxy running that only hits my node.js server for paths that being with /mysubdir
How do I get socket.io configured for this situation?
在我的客户代码中,我尝试过:
In my client code I tried:
var socket = io.connect('http://www.example.com/mysubdir');
但是随后我注意到底层的socket.io(或engine.io)http请求正在命中
but then I notice that the underlying socket.io (or engine.io) http requests are hitting
http://www.example.com/socket.io/?EIO=3&transport=polling&t=1410972713498-72`
我希望他们击中
http://www.example.com/mysubdir/socket.io.....
我必须在客户端和服务器上配置一些东西吗?
Is there something I have to configure on the client and the server?
推荐答案
在我的服务器中,我不得不
In my server I had to
var io = require('socket.io')(httpServer, {path: '/mysubdir/socket.io'})`
在我的客户中,我不得不
In my client I had to
<script src="http://www.example.com/mysubdir/socket.io/socket.io.js"></script>
还有
var socket = io.connect('http://www.example.com', {path: "/mysubdir/socket.io"});`
这篇关于我如何让socket.io运行一个子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文