fix: allow embedded worker API requests
ci/woodpecker/push/ci Pipeline failed
ci/woodpecker/tag/release-backend Pipeline was successful

This commit is contained in:
justme committed 2026-10-02 14:12:14 +08:00
1 parent 10ea48bf04
commit c68acfd78b
2 files changed
+8 -3

No files matched your search

+5 -2
View File
@@ -1,7 +1,7 @@
import { supportsApiContract } from '../contract';
export type ApiError = Error & { status?: number; code?: string };
let apiBase = '/api/v1';
let apiBase = new URL('/api/v1', self.location.origin).toString();
let contractCheck: Promise<void> | undefined;
export function setApiBase(value: string): void {
@@ -11,7 +11,10 @@ export function setApiBase(value: string): void {
}
export const fail = (status: number, code: string): ApiError => Object.assign(new Error(code), { status, code });
export const apiPath = (path: string): string => `${apiBase.replace(/\/$/, '')}${path}`;
export const apiPath = (path: string): string => new URL(
`${apiBase.replace(/\/$/, '')}${path}`,
self.location.origin,
).toString();
function ensureApiContract(): Promise<void> {
contractCheck ??= fetch(apiPath('/info'), {