mirror of
https://github.com/owntracks/frontend.git
synced 2026-08-25 20:47:16 +00:00
Return URL instance from getApiUrl
This commit is contained in:
+1
-1
@@ -6,7 +6,7 @@ export const getApiUrl = path => {
|
||||
? config.api.baseUrl.slice(1)
|
||||
: config.api.baseUrl;
|
||||
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
||||
return `${normalizedBaseUrl}${normalizedPath}`;
|
||||
return new URL(`${normalizedBaseUrl}${normalizedPath}`);
|
||||
};
|
||||
|
||||
export const isIsoDate = s => ISO_DATE_REGEXP.test(s);
|
||||
|
||||
+8
-6
@@ -9,16 +9,18 @@ import {
|
||||
describe("getApiUrl", () => {
|
||||
test("without base URL", () => {
|
||||
// See testURL in jest.config.js
|
||||
expect(getApiUrl("foo")).toBe("http://localhost/foo");
|
||||
expect(getApiUrl("/foo")).toBe("http://localhost/foo");
|
||||
expect(getApiUrl("/foo/bar")).toBe("http://localhost/foo/bar");
|
||||
expect(getApiUrl("foo").href).toBe("http://localhost/foo");
|
||||
expect(getApiUrl("/foo").href).toBe("http://localhost/foo");
|
||||
expect(getApiUrl("/foo/bar").href).toBe("http://localhost/foo/bar");
|
||||
});
|
||||
|
||||
test("with base URL", () => {
|
||||
config.api.baseUrl = "http://example.com/owntracks";
|
||||
expect(getApiUrl("foo")).toBe("http://example.com/owntracks/foo");
|
||||
expect(getApiUrl("/foo")).toBe("http://example.com/owntracks/foo");
|
||||
expect(getApiUrl("/foo/bar")).toBe("http://example.com/owntracks/foo/bar");
|
||||
expect(getApiUrl("foo").href).toBe("http://example.com/owntracks/foo");
|
||||
expect(getApiUrl("/foo").href).toBe("http://example.com/owntracks/foo");
|
||||
expect(getApiUrl("/foo/bar").href).toBe(
|
||||
"http://example.com/owntracks/foo/bar"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user