Testing getLowerEnvSubdomain

node v18.11.0
version: 2.0.0
endpointsharetweet
const urls = [ 'dev-box-4.int.fakeCompany-comm-nonprod.com', 'feature2-fxweb.fakeCompany-comm-nonprod.com', 'feature-fxweb.fakeCompany-comm-nonprod.com', 'olb-dev.int.fakeCompany-comm-nonprod.com', 'olb3-dev.int.fakeCompany-comm-nonprod.com', 'qa-fxweb.fakeCompany-comm-nonprod.com' ]; const environment = { rtpApiPartialUrl: 'fakeCompany-comm-nonprod.com/bears', envSubDomains: { dev: 'dev-adb-services', cat: 'qa2-adb-services', qa: 'qa2-adb-services', feature: 'qa2-adb-services', } }; function getLowerEnvSubdomain(hostnameStr) { const hostname = hostnameStr || window.location.hostname; //TODO remove after testing const domainParts = hostname.split('.'); if (domainParts.length < 2) return ''; const subdomain = domainParts[0] || ''; const subdomainParts = subdomain.split('-'); if (!subdomain || !subdomainParts.length) return ''; const isOlbEnv = subdomainParts[0].includes('olb'); // for Envs like olb3-dev const envSubdomainPart = isOlbEnv ? subdomainParts[1] : subdomainParts[0]; switch (true) { case envSubdomainPart.includes('dev'): return environment.envSubDomains.dev; case envSubdomainPart.includes('feature'): return environment.envSubDomains.feature; case envSubdomainPart.includes('qa'): return environment.envSubDomains.qa; case envSubdomainPart.includes('cat'): return environment.envSubDomains.cat; default: return ''; } } for(let url of urls) { const env = getLowerEnvSubdomain(url); console.log(env); }
Loading…

no comments

    sign in to comment