我遇到了Express.io的問題,我嘗試創建一個簡單的tchat。但我不能包括socket.io.js,我得到了一個錯誤...Express.io,socket.io.js找不到
我剛在我的新Express項目上安裝了Express.io。
我的錯誤:
- GET HTTP:// * ** /socket.io/socket.io.js 404(未找到)
- 本地主機:1未捕獲的ReferenceError:IO沒有定義
Index.jade
doctype 5
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
body
block content
script(src="http://localhost:3000/socket.io/socket.io.js")
script(src="/javascripts/user.js")
app.js
/**
* Module dependencies.
*/
var express = require('express.io')
, index = require('./routes/index.js')
, http = require('http')
, path = require('path');
var app = express();
app.http().io();
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(app.router);
app.use(express.static(path.join(__dirname, 'public')));
});
app.configure('development', function(){
app.use(express.errorHandler());
});
app.get('/', index.index);
app.io.route('ready', function(req) {
req.io.emit('talk', {
message: 'io event from an io route on the server'
});
});
http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});
index.js(路線)
exports.index = function(req, res){
res.render('index', {
title: 'TCHAT'
});
};
user.js的
io = io.connect();
// Emit ready event.
io.emit('ready');
// Listen for the talk event.
io.on('talk', function(data) {
alert(data.message);
});
新的錯誤
未能加載資源:// *::3000/socket.io.js 未捕獲的ReferenceError:未定義IO
什麼是你的節點的版本?在嘗試複製時,在節點0.6.18上的socket.io-client期間,我得到了一個npm安裝錯誤,如果您使用的是0.6.x版本,則可以解釋這些錯誤 – generalhenry 2013-03-15 03:43:23
我正在使用v0.8.15。 – tonymx227 2013-03-15 03:53:46
嘗試在根目錄中包含'socket.io.js',就像使用'user.js':'腳本(src =「/ socket.io/socket.io.js」)''一樣。 – 2013-03-15 04:15:01