Skip to content

Commit 001fbd9

Browse files
refactor: join API url using helper
1 parent 0dd8cdf commit 001fbd9

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

src/composables/useKirbyApi.js

+10-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { $fetch } from "ohmyfetch";
2-
import { withQuery } from "ufo";
1+
import { $fetch } from "ofetch";
2+
import { joinURL, withQuery } from "ufo";
33
import { useLanguages } from "./";
44

55
const cache = new Map();
@@ -12,20 +12,14 @@ const cache = new Map();
1212
*/
1313
function getApiUrl(path) {
1414
const { isMultilang, languageCode } = useLanguages();
15-
let result = "";
16-
17-
// Add language path in multi-language setup
18-
if (isMultilang) {
19-
result += `/${languageCode}`;
20-
}
21-
22-
// Add the API path
23-
result += `/${import.meta.env.VITE_BACKEND_API_SLUG}`;
24-
25-
// Add the file path
26-
result += `/${path}`;
27-
28-
return result;
15+
return joinURL(
16+
// Add language path in multi-language setup
17+
isMultilang ? `/${languageCode}` : "",
18+
// Add the API path
19+
import.meta.env.VITE_BACKEND_API_SLUG,
20+
// Add the file path
21+
path
22+
);
2923
}
3024

3125
/**

0 commit comments

Comments
 (0)