Add getApiKey method to HttpClient and update PubSubClient to use it for authentication. Change WebSocket URL from localhost to 127.0.0.1 for improved compatibility.

This commit is contained in:
anonpenguin23 2025-10-29 06:53:49 +02:00
parent 5c564b6327
commit fa357668cb
2 changed files with 12 additions and 3 deletions

View File

@ -82,6 +82,10 @@ export class HttpClient {
return this.jwt || this.apiKey;
}
getApiKey(): string | undefined {
return this.apiKey;
}
async request<T = any>(
method: "GET" | "POST" | "PUT" | "DELETE",
path: string,
@ -105,6 +109,10 @@ export class HttpClient {
...options.headers,
};
if (path.startsWith("/v1/pubsub/publish")) {
console.log("publish headers", headers);
}
// Debug: Log headers being sent
if (
typeof console !== "undefined" &&

View File

@ -119,18 +119,19 @@ export class PubSubClient {
} = {}
): Promise<Subscription> {
// Build WebSocket URL for this topic
const wsUrl = new URL(this.wsConfig.wsURL || "ws://localhost:6001");
const wsUrl = new URL(this.wsConfig.wsURL || "ws://127.0.0.1:6001");
wsUrl.pathname = "/v1/pubsub/ws";
wsUrl.searchParams.set("topic", topic);
const authToken = this.httpClient.getApiKey() ?? this.httpClient.getToken();
// Create WebSocket client
const wsClient = new WSClient({
...this.wsConfig,
wsURL: wsUrl.toString(),
authToken: this.httpClient.getToken(),
authToken,
});
console.log("[PubSubClient] Connecting to topic:", topic);
await wsClient.connect();
// Create subscription wrapper