Update Websocket Connection without VITE in PROD/DEV

main
boban 2025-09-28 23:25:22 +02:00
parent 3d3ea31e7a
commit af735c5012
4 changed files with 65 additions and 18 deletions

View File

@ -27,11 +27,12 @@ return [
*/
'servers' => [
'reverb' => [
'host' => env('REVERB_SERVER_HOST', '127.0.0.1'),
'port' => env('REVERB_SERVER_PORT', 8080),
'path' => env('REVERB_SERVER_PATH', '/ws'),
'scheme' => env('REVERB_SERVER_SCHEME', 'https'),
'key' => env('REVERB_APP_KEY'),
'hostname' => env('REVERB_HOST'),
'options' => [
'tls' => [],

View File

@ -0,0 +1,46 @@
// resources/js/plugins/connector.js
function readMetaConfig() {
const el = (typeof document !== 'undefined')
? document.querySelector('meta[name="reverb"]')
: null;
if (!el) return null;
const { host, port, scheme, path, key } = el.dataset; // data-*
return {
host: host || null,
port: port ? Number(port) : null,
scheme: scheme || null,
path: path || null,
key: key || null,
};
}
function readViteEnv() {
const env = (typeof import.meta !== 'undefined' && import.meta.env) ? import.meta.env : {};
return {
host: env.VITE_REVERB_HOST || env.APP_HOST || '127.0.0.1',
port: env.VITE_REVERB_PORT ? Number(env.VITE_REVERB_PORT) : 443,
scheme: (env.VITE_REVERB_SCHEME || 'https').toLowerCase(),
path: env.VITE_REVERB_PATH || '/ws',
key: env.VITE_REVERB_APP_KEY || 'mailwolt-yhp47tbt1aebhr1fgvgj',
};
}
function normalize(cfg) {
const c = { ...cfg };
if (!c.path || typeof c.path !== 'string') c.path = '/ws';
if (!c.path.startsWith('/')) c.path = '/' + c.path;
c.wsScheme = (c.scheme === 'http' ? 'ws' : 'wss');
return c;
}
const fromMeta = readMetaConfig();
const base = fromMeta ?? readViteEnv();
export const wsConfig = normalize({
host: base.host || '127.0.0.1',
port: base.port || 443,
scheme: base.scheme || 'https',
path: base.path || '/ws',
key: base.key || 'mailwolt-yhp47tbt1aebhr1fgvgj',
});

View File

@ -1,19 +1,23 @@
import Echo from 'laravel-echo'
import Pusher from 'pusher-js'
import {wsConfig} from "./connector.js";
window.Pusher = Pusher
const host = import.meta.env.VITE_REVERB_HOST || window.location.hostname
const port = Number(import.meta.env.VITE_REVERB_PORT) || 443
const scheme = (import.meta.env.VITE_REVERB_SCHEME || 'https').toLowerCase()
const host = wsConfig.host || window.location.hostname
const port = Number(wsConfig.port) || 443 // <- post -> port
const scheme = (wsConfig.scheme || 'https').toLowerCase()
const path = wsConfig.path || '/ws'
const tls = scheme === 'https'
const key = wsConfig.key
window.Echo = new Echo({
broadcaster: 'reverb',
key: import.meta.env.VITE_REVERB_APP_KEY,
key,
wsHost: host,
wsPort: port,
wssPort: port,
forceTLS: tls,
enabledTransports: ['ws','wss'],
wsPath: import.meta.env.VITE_REVERB_PATH || '/ws',
enabledTransports: ['ws', 'wss'],
wsPath: path,
})

View File

@ -41,6 +41,12 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="reverb"
data-host="{{ config('reverb.servers.reverb.host') }}"
data-port="{{ config('reverb.servers.reverb.port') }}"
data-scheme="{{ config('reverb.servers.reverb.scheme') }}"
data-path="{{ config('reverb.servers.reverb.path') }}"
data-key="{{ config('reverb.servers.reverb.key') }}">
<title>@yield('title', config('app.name'))</title>
@vite(['resources/css/app.css','resources/js/app.js'])
@livewireStyles
@ -65,18 +71,8 @@
{{-- Seite: immer auf volle Höhe und zentriert --}}
<main class="min-h-[calc(100dvh-64px)] grid place-items-center px-4">
<livewire:system.toast-hub />
{{-- <livewire:system.task-toast :taskKey="'issue-cert:mail.example.com'" />--}}
{{-- @dd(request('task'))--}}
{{-- @if (request('task'))--}}
{{-- <livewire:system.task-toast :taskKey="request('task')" />--}}
{{-- @endif--}}
{{-- <livewire:system.toast-hub/>--}}
<div id="toastra-root" class="absolute pointer-events-none"></div>
{{-- <livewire:system.task-toast :taskKey="'issue-cert:mail.example.com'" />--}}
{{-- @include('livewire.system.task-toast')--}}
{{--@if (request('task'))--}}
{{-- <livewire:system.task-toast :taskKey="request('task')" />--}}
{{-- @endif--}}
@yield('content')
</main>