fix: normalize base URL in SeerrApi constructor to ensure protocol prefix

This commit is contained in:
Uruk
2026-01-14 21:50:18 +01:00
parent 391ca897a5
commit 9a17e36882

View File

@@ -111,12 +111,27 @@ export type TestResult =
isValid: false; isValid: false;
}; };
/**
* Normalizes a URL by ensuring it has a protocol prefix (https:// or http://)
* @param url - The URL to normalize
* @returns The normalized URL with protocol prefix
*/
function normalizeUrl(url: string): string {
const trimmed = url.trim().replace(/\/+$/, ""); // Remove trailing slashes
if (trimmed.match(/^https?:\/\//i)) {
return trimmed;
}
// Default to https if no protocol is specified
return `https://${trimmed}`;
}
export class SeerrApi { export class SeerrApi {
axios: AxiosInstance; axios: AxiosInstance;
constructor(baseUrl: string) { constructor(baseUrl: string) {
const normalizedUrl = normalizeUrl(baseUrl);
this.axios = axios.create({ this.axios = axios.create({
baseURL: baseUrl, baseURL: normalizedUrl,
withCredentials: true, withCredentials: true,
withXSRFToken: true, withXSRFToken: true,
xsrfHeaderName: "XSRF-TOKEN", xsrfHeaderName: "XSRF-TOKEN",