UNPKG

@hhgtech/hhg-components

Version:
62 lines (57 loc) 2.62 kB
'use strict'; var constantsDomainLocales = require('./constantsDomainLocales.js'); var constantsIsProduction = require('./constantsIsProduction.js'); const getCurrentBaseUrl = (locale, isMarryBaby) => { const isDev = process.env.NEXT_PUBLIC_DEPLOY_ENV === 'development'; const isStaging = !isDev && !constantsIsProduction.isProduction; // const isDev = false // const isStaging = false return isDev ? 'http://localhost:3000' : `https://${isStaging ? isMarryBaby ? 'fe.' : 'discover.' : isMarryBaby ? 'www.' : ''}${constantsDomainLocales.domainLocales[isMarryBaby ? 'vi-VN_MB' : locale]}`; }; const getCurrentSsoUrl = (locale, isMarryBaby) => { return (process.env.UNIFY_SSO_API || `https://${!constantsIsProduction.isProduction ? 'staging-id.' : 'id.'}${constantsDomainLocales.domainLocales[isMarryBaby ? 'vi-VN_MB' : locale]}`); }; const getTogetherApiDomain = () => { return (process.env.UNIFY_INTERNAL_TOGETHER_API || process.env.UNIFY_TOGETHER_API || `https://${!constantsIsProduction.isProduction ? 'staging-together.' : 'together.'}hellohealthgroup.com`); }; const getDiscoverApiDomain = (locale) => { const isMarryBaby = locale.endsWith('_MB'); if (isMarryBaby) return `https://${!constantsIsProduction.isProduction ? 'staging.' : 'wp.'}${constantsDomainLocales.domainLocales[locale]}`; return (process.env.UNIFY_INTERNAL_DISCOVER_API || process.env.UNIFY_DISCOVER_API || `https://${!constantsIsProduction.isProduction ? 'staging.' : 'wp.'}${constantsDomainLocales.domainLocales[locale]}`); }; const getCareApiDomain = () => { return (process.env.UNIFY_INTERNAL_CARE_API || process.env.UNIFY_CARE_API || `https://${!constantsIsProduction.isProduction ? 'service-health-care.' : 'health-care.'}hellohealthgroup.com`); }; // remove accidental double continuous slash in url const normalizeLinkSlash = (link) => { return link.replace(/([^:]\/)\/+/g, '$1'); }; const forceEndSlash = (link) => { return link.replace(/\/?$/, '/'); }; const normalizeLink = (link) => { return normalizeLinkSlash(forceEndSlash(link)); }; exports.getCareApiDomain = getCareApiDomain; exports.getCurrentBaseUrl = getCurrentBaseUrl; exports.getCurrentSsoUrl = getCurrentSsoUrl; exports.getDiscoverApiDomain = getDiscoverApiDomain; exports.getTogetherApiDomain = getTogetherApiDomain; exports.normalizeLink = normalizeLink; exports.normalizeLinkSlash = normalizeLinkSlash;