用socket.io,浏览器怎么总是提示找到不到客户端脚本socket.io.js
发布于 11 年前 作者 skytouchzyt 6129 次浏览 最后一次编辑是 8 年前

服务器端提示:GET /socket.io/socket.io.js 404 1ms 代码如下:express自动创建的 app.set(‘port’, process.env.PORT || 3000); app.set(‘views’, __dirname + ‘/views’); app.set(‘view engine’, ‘jade’); app.use(express.favicon()); app.use(express.logger(‘dev’)); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(app.router); app.use(express.static(path.join(__dirname, ‘public’)));

// development only if (‘development’ == app.get(‘env’)) { app.use(express.errorHandler()); }

app.get(’/’, routes.index); app.get(’/users’, user.list);

http.createServer(app).listen(app.get(‘port’), function(){ console.log('Express server listening on port ’ + app.get(‘port’)); });

var io = require(‘socket.io’).listen(app);

模板文件 doctype 5 html head title= title link(rel=‘stylesheet’, href=’/stylesheets/style.css’) script(type=‘text/javascript’,src=‘socket.io/socket.io.js’) script(type=‘text/javascript’,scr=’/javascripts/jquery-1.9.1.min.js’) script(type=‘text/javascript’,src=’/javascripts/client.js’) body block content

1 回复

后面两段代码换成这样试试:

var server = http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});

var io = require('socket.io').listen(server);
回到顶部