weixin_33721344 2014-08-30 20:57 采纳率: 0%
浏览 37

Pusher / auth 404

I'm trying to establish a private channel using Pusher on a local node.js server. For some reason, I can't get my auth endpoint to play nice and I keep getting a 404 error.

At first I thought it was an issue with how I was defining my endpoint in relation to the location of the local server, but I don't think that's problem. More likely, my noobiness with server-client-api communication means I'm missing some big piece.

I've looked through the authentication docs on pusher and literally every SO thread I could find, but to no avail.

I've got node installed and the server running, and pusher recognizes that a connection is made, I'm just failing at the authentication.

Any help at all would be mightily appreciated.

Here's the client-side JS that is called when a button is clicked over at index.html:

In client.js:

    function startGame(){
    var nameinput = prompt("Give your game a name","My Game");
    if (nameinput !== null) {
        var initialsinput = prompt("What are your initials?", "MG");
        if (initialsinput !== null) {
            var pusher = new Pusher(key);
            Pusher.channel_auth_endpoint = 'http://localhost:8080/pusher/auth.js';
            var channel = pusher.subscribe("private-"+gamename);
            joined = 'client-opponent_joined'+gamename;
            channel.bind('client-opponent_joined'+gamename, function(data) {
                OnLikeDonkeyKong(data.nameinput,data.initialsinput);
            });
        }
        else {alert("I need your initials.");}
    }
    else {alert ("I need a game name.");}
}

Then, over in /pusher/auth.js:

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

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

    var pusher = new Pusher( { appId: 'xxx', key: 'xxx', secret: 'xxx' } );

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

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

Finally, here's the error I'm getting:

POST http://localhost:8080/pusher/auth.js 404 (Not Found) 
  • 写回答

1条回答 默认 最新

  • 衫裤跑路 2016-05-25 07:48
    关注

    http://localhost:8080/pusher/auth.js

    This url is not exist on server. Check the location of auth.js again.

    From Pusher document (link)

    authEndpoint (String)

    Endpoint on your server that will return the authentication signature needed for private and presence channels. Defaults to '/pusher/auth'.

    So you need to create your authentication endpoint on your server and provide a link to it while setup Pusher instance to authenticate.

    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧