mirror of
https://github.com/DeBrosOfficial/network-ts-sdk.git
synced 2025-12-11 01:58:49 +00:00
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:
parent
5c564b6327
commit
fa357668cb
@ -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" &&
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user