# PlayPay realtime

Socket.IO only transports events. Laravel validates users, persists messages and
publishes events to this service through the protected `/publish` endpoint.

## Environment

Use the same long random secret for Laravel and the Node process:

```env
# backend/.env
REALTIME_PUBLISH_URL=http://127.0.0.1:3001/publish
REALTIME_INTERNAL_SECRET=replace-with-a-long-random-value
```

```bash
export REALTIME_PORT=3001
export REALTIME_INTERNAL_SECRET=replace-with-the-same-long-random-value
export LARAVEL_REALTIME_AUTH_URL=http://127.0.0.1:8000/realtime/auth
export REALTIME_ALLOWED_ORIGINS=https://playpay.store
npm run realtime
```

## Nginx

Proxy the public Socket.IO path to the local process:

```nginx
location /socket.io/ {
    proxy_pass http://127.0.0.1:3001;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
    proxy_read_timeout 65s;
}
```

Run `npm run realtime` under systemd or Supervisor in production so it restarts
automatically. After changing Laravel environment values, run
`php artisan config:clear` (or rebuild the production config cache).
