fix paths

This commit is contained in:
Aarni Halinen
2022-01-14 01:34:39 +02:00
parent 394b7300af
commit 191fedfbc8
+5 -5
View File
@@ -55,8 +55,8 @@ const getHeaders = (auth?: boolean): Headers => {
const fillUrlParams = (apiPath: APIPath, params: API["urlParams"] = {}): string => {
const path = apiPath
.split("/")
.filter(Boolean)
.split("/") // ["", jobads", ":id"]
.filter(Boolean) // [jobads", ":id"]
.map((urlComponent) => {
// fill in each placeholder component like ':id' with value from params
if (urlComponent.startsWith(":")) {
@@ -66,9 +66,9 @@ const fillUrlParams = (apiPath: APIPath, params: API["urlParams"] = {}): string
}
return urlComponent;
})
.join("/");
// code above strips leading '/' from path
return `/${path}`;
.join("/"); // "jobads/:id"
// code above strips leading and trailing '/' from path
return `/${path}/`;
};
const callBackendAPI = async <RequestType, ResponseType>(