node.js - 找不到socket.io 404

时间:2014-10-31 15:37:22

标签: node.js express socket.io

我使用快递3.x.加载socket.io客户端给我一个404错误。

app.js

var express =       require('express'),
app =           express(),
http =          require('http'),
path =          require('path'),
favicon =       require('static-favicon'),
logger =        require('morgan'),
cookieParser =  require('cookie-parser'),
bodyParser =    require('body-parser'),
server =        http.createServer(app),
io =            require('socket.io').listen(server);

server.listen(app.get('port'));

//connecting to server
io.listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});

//read to client
server.on('connection', function (socket) {
    console.log('DAMN RIGHT');
    socket.emit('news', {message: 'DAMN RIGHT'});
});

.jade

doctype html
html
  head
    title= title
    link(rel='stylesheet', href='/stylesheets/style.css')
    script(src="./socket.io/socket.io.js")
  body
    div#template
    div#startscreen

    block content

浏览器显示找不到socket.io 404。

1 个答案:

答案 0 :(得分:1)

尝试删除.并检查

script(src='/socket.io/socket.io.js')

您可以also使用您的socket.io服务器来提供JS

script(src='http://localhost:port/socket.io/socket.io.js')

您可以also使用CDN

script(src='https://cdn.socket.io/socket.io-1.2.0.js')