fix(frontend): connecter le WS live sur /api/ws conforme au contrat (#13)
Le client live visait /ws/live alors que le serveur expose /api/ws : la connexion échouait et la reconnexion bouclait en permanence. Chemin corrigé et extrait en constante WS_PATH, avec deux tests de non-régression sur l'URL construite. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
* WebSocket live client for the web transport — ticket #13, lot F3 (finalised
|
||||
* from the F1 skeleton).
|
||||
*
|
||||
* Owns a single WS connection to `{wsUrl}/ws/live` (authenticated by the session
|
||||
* Owns a single WS connection to `{wsUrl}/api/ws` (authenticated by the session
|
||||
* cookie at the upgrade — same-origin, no URL secret) and multiplexes over it,
|
||||
* aligned on the **B5 frozen frame contract** (`crates/app-tauri/src/server.rs`):
|
||||
*
|
||||
@ -42,6 +42,16 @@ import {
|
||||
type StatusPayload,
|
||||
} from "./frames";
|
||||
|
||||
/**
|
||||
* Live WebSocket route — must match the server's `WS_PATH`
|
||||
* (`crates/app-tauri/src/server.rs`). Any other path is not recognised as an
|
||||
* upgrade and falls through to the SPA static fallback (a `200 index.html`), so
|
||||
* the socket never opens and the client reconnects forever behind a permanent
|
||||
* "connexion perdue" banner. Named once so the token/no-token branches below
|
||||
* cannot drift apart.
|
||||
*/
|
||||
const WS_PATH = "/api/ws";
|
||||
|
||||
/** Minimal WebSocket surface used here; injectable so tests pass a fake. */
|
||||
export interface WebSocketLike {
|
||||
send(data: string): void;
|
||||
@ -244,8 +254,8 @@ export class WsLiveClient {
|
||||
// Prod: the session cookie rides the upgrade (same-origin). The optional
|
||||
// token is a dev/test convenience only (never a prod secret in the URL).
|
||||
const url = this.token
|
||||
? `${this.wsUrl}/ws/live?token=${encodeURIComponent(this.token)}`
|
||||
: `${this.wsUrl}/ws/live`;
|
||||
? `${this.wsUrl}${WS_PATH}?token=${encodeURIComponent(this.token)}`
|
||||
: `${this.wsUrl}${WS_PATH}`;
|
||||
const socket = this.socketFactory(url);
|
||||
socket.onopen = () => {
|
||||
this.socket = socket;
|
||||
|
||||
Reference in New Issue
Block a user