找不到 socket.io.js [英] socket.io.js not found

查看:25
本文介绍了找不到 socket.io.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,我的节点服务器无法为路由 /socket.io/socket.io.js 提供服务,我总是收到 404 错误.
我尝试编译不同的节点版本(当前是 0.6.13,它也在服务器上运行,它实际上可以在服务器上运行).
从 app.js 我得到 info: socket.io started 并且在尝试调用 socket.io.js 时没有错误.

For some reason my node server cannot serve the route /socket.io/socket.io.js, I always get a 404 error.
I tried compiling different node versions (current is 0.6.13 which also runs on server, where it actually works).
From the app.js I get info: socket.io started and no error when trying to call the socket.io.js.

我从本地主机和端口 8000 尝试它并使用 express 框架

I try it from localhost and port 8000 and I use the express framework

这是来自 app.js 的代码:

This is the code from app.js:

var express = require('express')
  , app = require('express').createServer()
  , io = require('socket.io').listen(app, { log: true });

app.listen(8000);

app.configure(function() {
    app.use(express.static(__dirname + '/public'));
    app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

io.sockets.on('connection', function (socket) {
   // all other stuff here

推荐答案

请检查您的 Express 版本.Express 最近更新到 3.0alpha,其中 API 已更改.如果 3.0,您可以将代码更改为如下所示:

Please check your Express version. Express recently is updated to 3.0alpha which API was changed. If 3.0 you can change your code to something likes this:

var express = require('express')
  , http = require('http');

var app = express();
var server = http.createServer(app);
var io = require('socket.io').listen(server);

...

server.listen(8000);

与连接相同的问题:https://github.com/senchalabs/connect/issues/500#issuecomment-4620773

这篇关于找不到 socket.io.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆