POST http://localhost/broadcasting/auth 404 (Not Found) error

See original GitHub issue

I am trying to make my app connecting to pusher on a private channel.

But I am getting the following error in console:

POST http://localhost/broadcasting/auth 404 (Not Found) Pusher : Couldn’t retrieve authentication info. 404Clients must be authenticated to join private or presence channels

ChatEvent.php

<?php

namespace App\Events;

use App\User;

use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class ChatEvent implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;


   public $message;
   public $user;



    public function __construct($message, User $user)
    {

       $this ->message = $message;

        $this ->user = $user;


    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return Channel|array
     */
    public function broadcastOn()
    {
        return new PrivateChannel('chat');
    }
}

App.js

/**
 * First we will load all of this project's JavaScript dependencies which
 * includes Vue and other libraries. It is a great starting point when
 * building robust, powerful web applications using Vue and Laravel.
 */

require('./bootstrap');

window.Vue = require('vue');

import Vue from 'vue'
import VueChatScroll from 'vue-chat-scroll'
Vue.use(VueChatScroll)

/**
 * Next, we will create a fresh Vue application instance and attach it to
 * the page. Then, you may begin adding components to this application
 * or customize the JavaScript scaffolding to fit your unique needs.
 */

Vue.component('example', require('./components/Example.vue'));

Vue.component('chat-message', require('./components/ChatMessage.vue'));


const app = new Vue({
    el: '#app',

   data:{ 

    message:'',

     chat:{     

        message:[]

     } 

      },

   methods: {  send() { 

if(this.message.length !=0)
{

    this.chat.message.push(this.message);

    this.message= '';

}
   } },


   mounted()

   {

       Echo.private('chat')
    .listen('ChatEvent', (e) => {
        console.log(e.order.name);
    });

   } 

});

channels.php

<?php



Broadcast::channel('App.User.{id}', function ($user, $id) {
    return (int) $user->id === (int) $id;
});


Broadcast::channel('chat', function() {

return true;

});

ChatController.php

<?php

namespace App\Http\Controllers;

use App\Events\ChatEvent;
Use App\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;

class ChatController extends Controller
{


  public function __construct()

    {
        $this->middleware('auth');
    }


  public function chat()


  {

 return view('chat');

}


//public function send(Request $request)

//{

 // $user = User::find(Auth::id());

 // event(new ChatEvent($request -> $message, $user));

//}


public function send()

{

    $message = "Hello";

  $user = User::find(Auth::id());

  event(new ChatEvent( $message, $user));

}

}

bootstrap.js

window._ = require('lodash');

/**
 * We'll load jQuery and the Bootstrap jQuery plugin which provides support
 * for JavaScript based Bootstrap features such as modals and tabs. This
 * code may be modified to fit the specific needs of your application.
 */

try {
    window.$ = window.jQuery = require('jquery');

    require('bootstrap-sass');
} catch (e) {}

/**
 * We'll load the axios HTTP library which allows us to easily issue requests
 * to our Laravel back-end. This library automatically handles sending the
 * CSRF token as a header based on the value of the "XSRF" token cookie.
 */

window.axios = require('axios');

window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

/**
 * Next we will register the CSRF Token as a common header with Axios so that
 * all outgoing HTTP requests automatically have it attached. This is just
 * a simple convenience so we don't have to attach every token manually.
 */

let token = document.head.querySelector('meta[name="csrf-token"]');

if (token) {
    window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;
} else {
    console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token');
}

/**
 * Echo exposes an expressive API for subscribing to channels and listening
 * for events that are broadcast by Laravel. Echo and event broadcasting
 * allows your team to easily build robust real-time web applications.
 */

import Echo from 'laravel-echo'

 window.Pusher = require('pusher-js');

 window.Echo = new Echo({
     broadcaster: 'pusher',
     key: '815bcd2378a647ffaad7',
      cluster: 'ap2',
    encrypted: false
 });

what may be the cause for this error? any solution

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:29 (2 by maintainers)

github_iconTop GitHub Comments

22reactions
etdtecommented, Nov 22, 2017

Inside your config/app.php uncomment line with

App\Providers\BroadcastServiceProvider::class,
18reactions
razvysb93commented, Aug 16, 2018

Try adding: Broadcast::routes(); to /your project /routes/web.php then if you get “broadcasting/auth 403 (Forbidden)” try changing Broadcast::routes(); to Broadcast::routes(['middleware' => ['auth:api']]);

Read more comments on GitHub >

github_iconTop Results From Across the Web

laravel - http://localhost:8000/broadcasting/auth 404 (Not Found)
You need to set up an HTTP server running on localhost:8000 which can handle requests to /broadcasting/auth . The Pusher server libraries provide...
Read more >
POST http://localhost/broadcasting/auth 404 (Not Found)
Basically you need to make sure you enable the BroadcastServiceProvider and have the Broadcast::routes() method in there. No, I have checked I Broadcast:: ......
Read more >
POST http://localhost/broadcasting/auth 404 (Not Found) error ...
404 Error means that the route you're sending the call is not registered. I had a similar problem and it was solved by...
Read more >
Laravel – http://localhost:8000/broadcasting/auth 404 (Not ...
I am trying to make my app app connect to pusher on a private channel. ... What maybe the cause of the error...
Read more >
エラー POST http://localhost/broadcasting/auth 404 (Not ... - Qiita
エラー POST http://localhost/broadcasting/auth 404 (Not Found) error · reason 1 · reason 2.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found