Made the Redis port and Peerjs url settable through env variables

pull/313/head
fabawi 5 months ago
parent 0e63eb338b
commit 3fb178554a

@ -4,8 +4,19 @@ const { ExpressPeerServer } = require('peer')
const app = express();
const server = app.listen(9000);
const peerServers = process.env.PEERJS_SERVERS
? process.env.PEERJS_SERVERS.split(',').map(url => url.trim())
: [];
if (peerServers.length > 0) {
app.use('/api/peerjs-servers', (req, res) => {
res.json({ servers: peerServers });
});
}
const peerServer = ExpressPeerServer(server, {
path: '/filepizza'
})
app.use('/peerjs', peerServer)
app.use('/peerjs', peerServer)

@ -2,7 +2,7 @@ services:
redis:
image: redis:latest
ports:
- 127.0.0.1:6379:6379
- 127.0.0.1:${REDIS_PORT:-6379}:6379
networks:
- filepizza
volumes:
@ -29,12 +29,13 @@ services:
- 127.0.0.1:8080:80
environment:
- PORT=80
- REDIS_URL=redis://redis:6379
- REDIS_URL=redis://redis:${REDIS_PORT:-6379}
- COTURN_ENABLED=true
- TURN_REALM=https://${HOST_DOMAIN}
- TURN_HOST=${HOST_DOMAIN}
- API_ORIGINS=${API_ORIGINS}
- CLOUDFLARE_TUNNEL=true
- PEERJS_SERVERS=${PEERJS_SERVERS:-}
networks:
- filepizza
depends_on:

@ -2,7 +2,7 @@ services:
redis:
image: redis:latest
ports:
- 127.0.0.1:6379:6379
- 127.0.0.1:${REDIS_PORT:-6379}:6379
networks:
- filepizza
volumes:
@ -28,11 +28,12 @@ services:
- 0.0.0.0:80:80
environment:
- PORT=80
- REDIS_URL=redis://redis:6379
- REDIS_URL=redis://redis:${REDIS_PORT:-6379}
- PEERJS_SERVERS=${PEERJS_SERVERS:-}
- COTURN_ENABLED=true
# - TURN_REALM=https://emaily.re
# - TURN_HOST=https://emaily.re
# - API_ORIGINS=https://emaily.re,https://texlyre.github.io
- TURN_REALM=https://${HOST_DOMAIN}
- TURN_HOST=${HOST_DOMAIN}
- API_ORIGINS=${API_ORIGINS}
networks:
- filepizza
depends_on:
@ -45,4 +46,4 @@ networks:
driver: bridge
volumes:
redis_data:
redis_data:

@ -2,7 +2,7 @@ services:
redis:
image: redis:latest
ports:
- 6379:6379
- ${REDIS_PORT:-6379}:6379
networks:
- filepizza
volumes:
@ -29,8 +29,9 @@ services:
- 8080:8080
environment:
- PORT=8080
- REDIS_URL=redis://redis:6379
- REDIS_URL=redis://redis:${REDIS_PORT:-6379}
- API_ORIGINS=http://localhost:8081
- PEERJS_SERVERS=${PEERJS_SERVERS:-}
networks:
- filepizza
depends_on:

@ -6,6 +6,10 @@ NODE_ENV=production
# Host Configuration
HOST_DOMAIN=filepizza.example.com
# PeerJS URL and Redis PORT
# REDIS_PORT=6379
# PEERJS_SERVERS=peerjs.mydomain:9000
# CORS Configuration
API_ORIGINS=https://filepizza.example.com,https://myapp.example.com,http://localhost:8081

@ -37,12 +37,34 @@ async function getOrCreateGlobalPeer(): Promise<Peer> {
const { iceServers } = await response.json()
console.log('[WebRTCProvider] ICE servers:', iceServers)
globalPeer = new Peer({
let peerConfig: any = {
debug: 3,
config: {
iceServers,
},
})
}
try {
const peerServersResponse = await fetch('/api/peerjs-servers')
if (peerServersResponse.ok) {
const { servers } = await peerServersResponse.json()
if (servers && servers.length > 0) {
const serverUrl = new URL(servers[0])
peerConfig = {
...peerConfig,
host: serverUrl.hostname,
port: serverUrl.port ? parseInt(serverUrl.port) : (serverUrl.protocol === 'https:' ? 443 : 80),
path: serverUrl.pathname,
secure: serverUrl.protocol === 'https:',
}
console.log('[WebRTCProvider] Using custom PeerJS server:', peerConfig)
}
}
} catch (error) {
console.log('[WebRTCProvider] No custom PeerJS servers configured, using default')
}
globalPeer = new Peer(peerConfig)
}
if (globalPeer.id) {

Loading…
Cancel
Save