我正在尝试按照此处的说明进行操作
但是,我似乎太笨了,无法理解为什么我不能在客户端引用 socket.io.jss。我在这里读过类似的帖子,但它们似乎不正确:NodeJS Express not serving '/socket.io/socket.io.js'
这是完整的应用列表:
var application_root = __dirname,
express = require('express'),
//Web framework
path = require('path'),
//Utilities for dealing with file paths
pg = require('pg'); //Postgres integration
//Create server
var app = express();
// Configure server
app.configure(function () {
//parses request body and populates request.body
app.use(express.bodyParser());
//checks request.body for HTTP method overrides
app.use(express.methodOverride());
//perform route lookup based on url and HTTP method
app.use(app.router);
//Where to serve static content
app.use(express.static(path.join(application_root, 'public')));
//Show all errors in development
app.use(express.errorHandler({
dumpExceptions: true,
showStack: true
}));
});
//Start server
var port = 4711;
app.listen(port, function () {
console.log('Express server listening on port %d in %s mode', port, app.settings.env);
});
//Start socket.io
var server = require('http').createServer(app),
io = require('socket.io').listen(server);
现在,如果我尝试引用客户端 js,我会得到 404。
<script src="/socket.io/socket.io.js"></script>
任何人都知道为什么 Express 3 不允许 socket.io 为其客户端库提供服务?