2014-07-15 2 views
1

인증 코드 node.js의 예가 pusher.com 인 경우 작동하지 않습니다.node.js에 대한 푸셔 인증 예제가 실패합니다.

var express = require('express'); 
var Pusher = require('pusher'); 

var app = express(express.logger()); 
app.use(express.bodyParser()); 

var pusher = new Pusher({ appId: APP_ID, key: APP_KEY, secret: APP_SECRET }); 

app.post('/pusher/auth', function(req, res) { 
    var socketId = req.body.socket_id; 
    var channel = req.body.channel_name; 
    var auth = pusher.auth(socketId, channel); 
    res.send(auth); 
}); 

var port = process.env.PORT || 5000; 
app.listen(port); 

다음 오류가 반환됩니다. 어떻게 해결할 수 있습니까?

TypeError: Object #<Pusher> has no method 'auth' 

답변

0

아, 어떤 이유로 그들은 를 인증인증에서 메소드 이름을 변경해야합니다.

다음은 제 고정 된 버전입니다. 참고 선 4 pusher.authenticate

app.post('/pusher/auth', function(req, res) { 
    var socketId = req.body.socket_id; 
    var channel = req.body.channel_name; 
    var auth = pusher.authenticate(socketId, channel); 
    res.send(auth); 
}); 

여기 내 pusher.js에 파일을 참조거야. 내 node_modules에서 로컬 :

/** Returns a signature for given socket id, channel and socket data. 
* 
* @param {String} socketId socket id 
* @param {String} channel channel name 
* @param {Object} [data] additional socket data 
* @returns {String} authentication signature 
*/ 
Pusher.prototype.authenticate = function(socketId, channel, data) { 
    return auth.getSocketSignature(this.config.token, channel, socketId, data); 
}; 

Pusher.js package.json

{ 
    "name": "pusher", 
    "description": "Node.js client to interact with the Pusher REST API", 
    "version": "1.0.0", 
    "author": { 
    "name": "Pusher", 
    "email": "[email protected]" 
    }, 
+0

확실히 여전히 방법/기능'auth'라고 한 푸셔 노드 서버 라이브러리입니다. https://github.com/pusher/pusher-node-server/blob/master/lib/pusher.js#L32 어떤 Node.js 패키지를 사용하고 있습니까?를 참조하십시오. – leggetter

+0

이상한 - 방금 'npm 설치 푸셔 - 저장'을했고 내 package.json은 '푸셔'를 보여줍니다 : "^ 1.0.0". 로컬 노드 모듈 디렉토리에서 소스를 확인하겠습니다. – treejanitor

+0

내 답변에 pusher.js 파일에서 관련 코드를 추가했습니다. 나는 이상한 일을하고 있니? 어쩌면 나는 '푸시 - 노드 - 서버'를 사용해야 할 것인가? – treejanitor

관련 문제