mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* metadata helpers and values for txs pages * update titles to the rest of the pages * refactor getServerSideProps * dynamically update metadata for token and dapp page * test * 404 error page * make new config * make use of new config, delete old one * feature reporter: dev implementation * feature reporter: docker integration * resctructure ENVS.md * sentry feature * refinements * add spaces between sections * tweaks * switch to camelCase * clean up * remove NEXT_PUBLIC_NETWORK_TOKEN_ADDRESS * v
27 lines
1.1 KiB
TypeScript
27 lines
1.1 KiB
TypeScript
import { compile } from 'path-to-regexp';
|
|
|
|
import config from 'configs/app';
|
|
|
|
import isNeedProxy from './isNeedProxy';
|
|
import { RESOURCES } from './resources';
|
|
import type { ApiResource, ResourceName, ResourcePathParams } from './resources';
|
|
|
|
export default function buildUrl<R extends ResourceName>(
|
|
resourceName: R,
|
|
pathParams?: ResourcePathParams<R>,
|
|
queryParams?: Record<string, string | Array<string> | number | null | undefined>,
|
|
): string {
|
|
const resource: ApiResource = RESOURCES[resourceName];
|
|
const baseUrl = isNeedProxy() ? config.app.baseUrl : (resource.endpoint || config.api.endpoint);
|
|
const basePath = resource.basePath !== undefined ? resource.basePath : config.api.basePath;
|
|
const path = isNeedProxy() ? '/node-api/proxy' + basePath + resource.path : basePath + resource.path;
|
|
const url = new URL(compile(path)(pathParams), baseUrl);
|
|
|
|
queryParams && Object.entries(queryParams).forEach(([ key, value ]) => {
|
|
// there are some pagination params that can be null or false for the next page
|
|
value !== undefined && value !== '' && url.searchParams.append(key, String(value));
|
|
});
|
|
|
|
return url.toString();
|
|
}
|