简体   繁体   English

POST pusher/auth 404(未找到)

[英]POST pusher/auth 404 (Not Found)

I'm trying to establish a private channel using Pusher on a local node.js server.我正在尝试在本地 node.js 服务器上使用 Pusher 建立一个私人频道。 For some reason, I can't get my auth endpoint to play nice and I keep getting a 404 error.出于某种原因,我无法让我的身份验证端点正常运行,并且不断收到 404 错误。

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 a problem.起初我认为这是我如何定义与本地服务器位置相关的端点的问题,但我认为这不是问题。 More likely, my noobiness with server-client-api communication means I'm missing some big piece.更有可能的是,我对服务器-客户端-api 通信的不了解意味着我错过了一些重要的东西。

I've looked through the authentication docs on Pusher and literally every SO thread I could find, but to no avail.我已经查看了 Pusher 上的身份验证文档以及我能找到的每个 SO 线程,但无济于事。

I've got Node installed and the server running, and Pusher recognizes that a connection is made, I'm just failing at the authentication.我已经安装了 Node 并且服务器正在运行,并且 Pusher 识别出建立了连接,我只是在身份验证中失败了。

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:这是在 index.html 中单击按钮时调用的客户端 JS:

In client.js:在 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:然后,在 /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) POST http://localhost:8080/pusher/auth.js 404(未找到)

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

This url is not exist on server.服务器上不存在此网址。 Check the location of auth.js again.再次检查 auth.js 的位置。

From Pusher document ( link )来自 Pusher 文档(链接

authEndpoint (String) authEndpoint(字符串)

Endpoint on your server that will return the authentication signature needed for private and presence channels.您服务器上的端点将返回私有和在线通道所需的身份验证签名。 Defaults to '/pusher/auth'.默认为“/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.因此,您需要在服务器上创建身份验证端点并在设置 Pusher 实例以进行身份​​验证时提供指向它的链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM