mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-16 11:50:42 +08:00
Fix bug with default ports in api config
JavaScript brilliance strikes again:
new URL("https://acme.com:443").port == ""
Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
+9
-7
@@ -1,6 +1,6 @@
|
||||
export interface Host {
|
||||
host: string;
|
||||
port: number;
|
||||
port: number | null;
|
||||
}
|
||||
|
||||
export async function get(
|
||||
@@ -23,24 +23,26 @@ export async function get(
|
||||
path = path.startsWith("/") ? path.slice(1) : path;
|
||||
|
||||
const baseUrl = path
|
||||
? `${protocol}${base}:${port}/v1/${path}`
|
||||
: `${protocol}${base}:${port}`;
|
||||
const url = search ? `${baseUrl}?${search}` : baseUrl;
|
||||
? `${protocol}${base}/v1/${path}`
|
||||
: `${protocol}${base}`;
|
||||
const url = new URL(search ? `${baseUrl}?${search}` : baseUrl);
|
||||
url.port = String(port);
|
||||
|
||||
const urlString = String(url);
|
||||
let response = null;
|
||||
try {
|
||||
response = await fetch(url, {
|
||||
response = await fetch(urlString, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
throw new ApiError(url, "API request failed");
|
||||
throw new ApiError(urlString, "API request failed");
|
||||
}
|
||||
|
||||
if (! response.ok) {
|
||||
throw new ApiError(url, "Not found");
|
||||
throw new ApiError(urlString, "Not found");
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user