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 fillUrlParams = (apiPath: APIPath, params: API["urlParams"] = {}): string => {
const path = apiPath const path = apiPath
.split("/") .split("/") // ["", jobads", ":id"]
.filter(Boolean) .filter(Boolean) // [jobads", ":id"]
.map((urlComponent) => { .map((urlComponent) => {
// fill in each placeholder component like ':id' with value from params // fill in each placeholder component like ':id' with value from params
if (urlComponent.startsWith(":")) { if (urlComponent.startsWith(":")) {
@@ -66,9 +66,9 @@ const fillUrlParams = (apiPath: APIPath, params: API["urlParams"] = {}): string
} }
return urlComponent; return urlComponent;
}) })
.join("/"); .join("/"); // "jobads/:id"
// code above strips leading '/' from path // code above strips leading and trailing '/' from path
return `/${path}`; return `/${path}/`;
}; };
const callBackendAPI = async <RequestType, ResponseType>( const callBackendAPI = async <RequestType, ResponseType>(