mirror of
https://github.com/DeBrosOfficial/network-ts-sdk.git
synced 2025-12-12 18:28:50 +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;
|
return this.jwt || this.apiKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getApiKey(): string | undefined {
|
||||||
|
return this.apiKey;
|
||||||
|
}
|
||||||
|
|
||||||
async request<T = any>(
|
async request<T = any>(
|
||||||
method: "GET" | "POST" | "PUT" | "DELETE",
|
method: "GET" | "POST" | "PUT" | "DELETE",
|
||||||
path: string,
|
path: string,
|
||||||
@ -105,6 +109,10 @@ export class HttpClient {
|
|||||||
...options.headers,
|
...options.headers,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (path.startsWith("/v1/pubsub/publish")) {
|
||||||
|
console.log("publish headers", headers);
|
||||||
|
}
|
||||||
|
|
||||||
// Debug: Log headers being sent
|
// Debug: Log headers being sent
|
||||||
if (
|
if (
|
||||||
typeof console !== "undefined" &&
|
typeof console !== "undefined" &&
|
||||||
|
|||||||
@ -119,18 +119,19 @@ export class PubSubClient {
|
|||||||
} = {}
|
} = {}
|
||||||
): Promise<Subscription> {
|
): Promise<Subscription> {
|
||||||
// Build WebSocket URL for this topic
|
// 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.pathname = "/v1/pubsub/ws";
|
||||||
wsUrl.searchParams.set("topic", topic);
|
wsUrl.searchParams.set("topic", topic);
|
||||||
|
|
||||||
|
const authToken = this.httpClient.getApiKey() ?? this.httpClient.getToken();
|
||||||
|
|
||||||
// Create WebSocket client
|
// Create WebSocket client
|
||||||
const wsClient = new WSClient({
|
const wsClient = new WSClient({
|
||||||
...this.wsConfig,
|
...this.wsConfig,
|
||||||
wsURL: wsUrl.toString(),
|
wsURL: wsUrl.toString(),
|
||||||
authToken: this.httpClient.getToken(),
|
authToken,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("[PubSubClient] Connecting to topic:", topic);
|
|
||||||
await wsClient.connect();
|
await wsClient.connect();
|
||||||
|
|
||||||
// Create subscription wrapper
|
// Create subscription wrapper
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user