mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* add prefix to API resources * fix pw tests * refactor config * remove unnecessary prefixes in resource names * fixes * update screenshots
23 lines
732 B
TypeScript
23 lines
732 B
TypeScript
import { compile } from 'path-to-regexp';
|
|
|
|
import getResourceParams from 'lib/api/getResourceParams';
|
|
import type { ResourceName } from 'lib/api/resources';
|
|
|
|
export default function buildUrl(
|
|
_resource: ResourceName,
|
|
pathParams?: Record<string, string | undefined>,
|
|
queryParams?: Record<string, string | number | undefined>,
|
|
) {
|
|
const { resource, api } = getResourceParams(_resource);
|
|
const baseUrl = api.endpoint;
|
|
const basePath = api.basePath ?? '';
|
|
const path = basePath + resource.path;
|
|
const url = new URL(compile(path)(pathParams), baseUrl);
|
|
|
|
queryParams && Object.entries(queryParams).forEach(([ key, value ]) => {
|
|
value && url.searchParams.append(key, String(value));
|
|
});
|
|
|
|
return url.toString();
|
|
}
|