NodeJS Express 不提供“/socket.io/socket.io.js" [英] NodeJS Express not serving '/socket.io/socket.io.js'
问题描述
我正在尝试构建 NodeJS/Express/SocketIO 应用程序.
I am trying to build NodeJS/Express/SocketIO application.
进口:
var express = require('express')
, app = express()
, server = require('http').createServer(app)
, io = require('socket.io').listen(server)...
配置:
app.configure(function(){
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(express.cookieParser('your secret here'));
app.use(express.session());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
});
在我的 Jade 模板中:
In my Jade template:
script(type='text/javascript', href='/socket.io/socket.io.js')
但是当我尝试访问它时,'/socket.io/socket.io.js' 不可用
But '/socket.io/socket.io.js' is not available when I am trying to reach it on
http://localhost:3000/socket.io/socket.io.js
正如它所说:
无法获取/socket.io/socket.io.js
Cannot GET /socket.io/socket.io.js
如何从已安装的模块提供 socket.io.js?
How do I serve socket.io.js from the installed module?
谢谢
推荐答案
您需要将客户端代码从 Socket.io 内部目录复制到您的公共目录.在 Socket 0.9 中,可分发文件的路径是 node_modules/socket.io/node_modules/socket.io-client/dist
.
You need to copy the client code from an inner Socket.io directory to your public directory. In Socket 0.9, the path to the distributable files is node_modules/socket.io/node_modules/socket.io-client/dist
.
这篇关于NodeJS Express 不提供“/socket.io/socket.io.js"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!