16 lines
718 B
TypeScript
16 lines
718 B
TypeScript
import { APIPathGen } from "./APIPathGen";
|
|
import type { APITail, RawArgType } from "../apiStructure/defs";
|
|
import { structure } from "../apiStructure/sammoRootAPI";
|
|
import { callClientAPI } from "./generator";
|
|
|
|
const apiRoot = process.env.API_ROOT_PATH ?? process.env.VITE_API_ROOT_PATH ?? '/rootAPI';
|
|
|
|
export const SammoRootAPI = APIPathGen(structure, (path: string[], tail: APITail, pathParam) => {
|
|
const method = tail.reqType;
|
|
return (args?: RawArgType, returnError?: boolean) => {
|
|
if (returnError) {
|
|
return callClientAPI(method, apiRoot, path.join('/'), args, pathParam, returnError);
|
|
}
|
|
return callClientAPI(method, apiRoot, path.join('/'), args, pathParam);
|
|
};
|
|
}); |