Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/scrawn/src/core/scrawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ export class Scrawn<
return this.apiKey;
}

/** Base URL for the HTTP API (derived from baseURL config) */
private httpUrl: string;

private sleep(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}
Expand Down Expand Up @@ -223,6 +226,7 @@ export class Scrawn<

this.apiKey = config.apiKey;
this.retryCount = config.retryCount ?? 2;
this.httpUrl = this.buildHttpUrl(config.baseURL);
this.grpcClient = new GrpcClient(this.parseURLToTarget(config.baseURL), {
secure: config.secure ?? true,
credentials: config.credentials,
Expand All @@ -245,6 +249,16 @@ export class Scrawn<
: `${baseURL}:${ScrawnConfig.grpc.defaultPort}`;
}

private buildHttpUrl(baseURL: string): string {
if (baseURL.includes("://")) {
const url = new URL(baseURL);
return `http://${url.hostname}:8070`;
}

const host = baseURL.includes(":") ? baseURL.split(":")[0] : baseURL;
return `http://${host}:8070`;
}

/**
* Create a type-safe tag reference.
*
Expand Down Expand Up @@ -1289,7 +1303,7 @@ export class Scrawn<
async webhook(request: Request): Promise<WebhookEvent> {
if (!this.cachedPublicKey) {
const response = await fetch(
"http://localhost:8070/api/v1/internals/webhook-endpoint/public-key",
`${this.httpUrl}/api/v1/internals/webhook-endpoint/public-key`,
{ headers: { Authorization: `Bearer ${this.apiKey}` } }
);
if (!response.ok)
Expand Down
Loading