code-withme-biz's avatar

How to make Laravel Reverb work in IIS production environment?

I have laravel 11 api only project. In the project I've integrated Laravel Reverb to make socket communication between Backend and Frontend. Frontend was developed in Vite/React. Both Backend and Frontend are running on the same server but still in decoupled architecture.

When the project is running locally Reverb is working fine as I can broadcast event from the backend and receive the data in the frontend through private channel.

This is my settings for Reverb in the Backend.

REVERB_APP_ID={*****}
REVERB_APP_KEY={*****}
REVERB_APP_SECRET={*****}
REVERB_HOST="localhost"
REVERB_PORT=8080
REVERB_SCHEME=http

And this is the settings for Reverb in the Frontend.

VITE_REVERB_APP_ID={*****}
VITE_REVERB_APP_KEY={*****}
VITE_REVERB_APP_SECRET={******}
VITE_REVERB_HOST="localhost"
VITE_REVERB_PORT=8080
VITE_REVERB_SCHEME=http

Code to connect to the reverb websocket from the Frontend.

import { useEffect, useState } from 'react'
import Echo from 'laravel-echo'

import Pusher from 'pusher-js'
import api from '../../utils/api'
window.Pusher = Pusher

const useEcho = () => {
    const [echoInstance, setEchoInstance] = useState(null)

    useEffect(() => {
        const echo = new Echo({
          broadcaster: 'reverb',
          key: import.meta.env.VITE_REVERB_APP_KEY,
          authorizer: (channel) => {
            return {
                authorize: (socketId, callback) => {
                    api.post('api/broadcasting/auth', {
                        socket_id: socketId,
                        channel_name: channel.name
                    })
                    .then(response => {
                        callback(false, response.data);
                    })
                    .catch(error => {
                        console.log(error);
                        callback(true, error);
                    });
                }
            };
          },
          wsHost: import.meta.env.VITE_REVERB_HOST,
          wsPort: import.meta.env.VITE_REVERB_PORT ?? 80,
          wssPort: import.meta.env.VITE_REVERB_PORT ?? 443,
          forceTLS: (import.meta.env.VITE_REVERB_SCHEME ?? 'https') === 'https',
          enabledTransports: ['ws', 'wss'],
        })
        setEchoInstance(echo)
    }, [])

    return echoInstance
}

export default useEcho

To deploy to IIS server, I enabled websocket protocol in IIS configuration settings. But websocket is not working yet. Is there any good reference how to config IIS to make reverb working?

Thank you in advance.

0 likes
1 reply

Please or to participate in this conversation.