0

私はapp.postのroutes.jsでイベントを発行しようとしていますが、このエラーが発生しました:メソッド「発行」がありません。

app.js :

app.io.route('setOnlineServer', function (req) {
Account.setOnline(req.user); 
});

ルート.js

app.post('/login', passport.authenticate('local'), function(req, res) {
    req.io.emit('setOnlineServer',req.user);
    res.redirect('/');
});

このようなユーザーを獲得できない場合。認証されたユーザーを取得するためのアイデアはありますか?

4

1 に答える 1

0

サーバー (app.js)

app = require('express.io')()
app.http().io()

// Broadcast the new visitor event on ready route.
app.io.route('ready', function(req) {
   req.io.broadcast('new visitor')
})

// Send client html.
app.get('/', function(req, res) {
res.sendfile(__dirname + '/client.html')
})

app.listen(7076)

クライアント (client.html)

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
io = io.connect()

// Send the ready event.
io.emit('ready')

// Listen for the new visitor event.
io.on('new visitor', function() {
    $('body').append('<p>New visitor, hooray! ' + new Date().toString() +'</p>')
})
</script>
于 2013-08-14T03:41:08.577 に答える