fix: normalize relay websocket endpoint

**Motivations :**
- ensure client always targets the correct /ws websocket path
- avoid invalid bootstrap URLs breaking relay connections

**Modifications :**
- sanitize bootstrap relay URLs and enforce /ws suffix when missing
- update documentation to reference wss://relay235.4nkweb.com/ws exactly
- align local env files with the normalized relay endpoint

**Page affectées :**
- src/services/service.ts
- README.md
- docs/INTEGRATION.md
This commit is contained in:
NicolasCantu 2025-10-31 14:07:38 +01:00
parent 274b19e410
commit 74093a12eb
3 changed files with 58 additions and 8 deletions

View File

@ -72,9 +72,9 @@ src/
- **Communication**: WebSockets, PostMessage API
### **WebSocket Relay Configuration**
- Default relay runs locally on `127.0.0.1:8091` and is exposed securely via `wss://relay235.4nkweb.com`
- Default relay runs locally on `127.0.0.1:8091` and is exposed securely via `wss://relay235.4nkweb.com/ws`
- Nginx TLS termination is defined in `nginx.relay235.conf` (kept alongside the existing `nginx.dev.conf`)
- Clients must configure `VITE_BOOTSTRAPURL=wss://relay235.4nkweb.com` to avoid mixed-content issues when the app is served over HTTPS
- Clients must configure `VITE_BOOTSTRAPURL=wss://relay235.4nkweb.com/ws` to avoid mixed-content issues when the app is served over HTTPS
## 🔧 Développement

View File

@ -109,9 +109,9 @@ Les styles s'adaptent automatiquement :
```
### 1.1 Relai WebSocket
- Relai principal exposé en `wss://relay235.4nkweb.com`
- Relai principal exposé en `wss://relay235.4nkweb.com/ws`
- Terminaison TLS gérée par `nginx.relay235.conf` (reverse proxy vers le service local sur `127.0.0.1:8091`)
- Variables denvironnement cliente à utiliser : `VITE_BOOTSTRAPURL=wss://relay235.4nkweb.com`
- Variables denvironnement cliente à utiliser : `VITE_BOOTSTRAPURL=wss://relay235.4nkweb.com/ws`
### 2. Intégration personnalisée
```html

View File

@ -24,11 +24,60 @@ import { DATABASE_CONFIG } from './database-config';
export const U32_MAX = 4294967295;
const BASEURL = import.meta.env.VITE_BASEURL || `http://localhost`;
const BOOTSTRAPURL = [import.meta.env.VITE_BOOTSTRAPURL || `${BASEURL}:8090`];
const BOOTSTRAPURL = sanitizeBootstrapUrls(
import.meta.env.VITE_BOOTSTRAPURL || `${BASEURL}:8090`
);
const STORAGEURL = import.meta.env.VITE_STORAGEURL || `${BASEURL}:8081`;
const BLINDBITURL = import.meta.env.VITE_BLINDBITURL || `${BASEURL}:8000`;
const DEFAULTAMOUNT = 1000n;
function sanitizeBootstrapUrls(rawUrls: string): string[] {
const urls = rawUrls
.split(',')
.map(url => url.trim())
.filter(url => url.length > 0)
.map(url => sanitizeBootstrapUrl(url));
if (urls.length === 0) {
throw new Error('No bootstrap relay URL configured (VITE_BOOTSTRAPURL)');
}
return urls;
}
function sanitizeBootstrapUrl(url: string): string {
const trimmed = url.trim();
if (trimmed.length === 0) {
throw new Error('Empty bootstrap relay URL provided');
}
let parsed: URL;
try {
parsed = new URL(trimmed);
} catch (error) {
secureLogger.error('Invalid bootstrap relay URL format', error as Error, {
component: 'Service',
data: trimmed,
});
throw error;
}
if (parsed.protocol !== 'ws:' && parsed.protocol !== 'wss:') {
throw new Error(`Invalid bootstrap relay protocol for ${trimmed}. Expected ws:// or wss://`);
}
if (!parsed.pathname || parsed.pathname === '/') {
parsed.pathname = '/ws';
} else if (parsed.pathname.endsWith('/ws/')) {
parsed.pathname = '/ws';
}
parsed.search = '';
parsed.hash = '';
return parsed.toString();
}
// Global loading spinner functions removed - now using updateUserStatus instead
// Helper function to update user status (can be called from static methods)
@ -326,7 +375,7 @@ export default class Services {
this.sdkClient = await import('../../pkg/sdk_client');
this.sdkClient.setup();
for (const wsurl of Object.values(BOOTSTRAPURL)) {
for (const wsurl of BOOTSTRAPURL) {
this.updateRelay(wsurl, '');
}
@ -617,10 +666,11 @@ export default class Services {
* @param spAddress - The SP Address (value).
*/
public updateRelay(url: string, spAddress: string) {
secureLogger.info(' Updating relay ${url} with spAddress ${spAddress}', {
const normalizedUrl = sanitizeBootstrapUrl(url);
secureLogger.info(' Updating relay ${normalizedUrl} with spAddress ${spAddress}', {
component: 'Service',
});
this.relayAddresses[url] = spAddress;
this.relayAddresses[normalizedUrl] = spAddress;
}
/**