2023-02-06 12:19:39 +03:00

37 lines
1.0 KiB
TypeScript

import { publicRuntimeConfigSchema, serverRuntimeConfigSchema } from './schema/runtime-config';
import urls from '@/constants/urls';
import getConfig from 'next/config';
import { isServer } from 'tools/common';
const { serverRuntimeConfig, publicRuntimeConfig } = getConfig();
function getUrls() {
const { BASE_PATH } = publicRuntimeConfigSchema.parse(publicRuntimeConfig);
if (isServer()) {
const { URL_CRM_GRAPHQL_DIRECT, URL_GET_USER_DIRECT, URL_CORE_FINGAP_DIRECT, PORT } =
serverRuntimeConfigSchema.parse(serverRuntimeConfig);
return {
BASE_PATH,
PORT,
URL_CORE_FINGAP: URL_CORE_FINGAP_DIRECT,
URL_CRM_GRAPHQL: URL_CRM_GRAPHQL_DIRECT,
URL_GET_USER: URL_GET_USER_DIRECT,
};
}
function withBasePath(url: string) {
return BASE_PATH + url;
}
return {
BASE_PATH,
URL_CORE_FINGAP: withBasePath(urls.URL_CORE_FINGAP_PROXY),
URL_CRM_GRAPHQL: withBasePath(urls.URL_CRM_GRAPHQL_PROXY),
URL_GET_USER: withBasePath(urls.URL_GET_USER_PROXY),
};
}
export default getUrls;