From e8a79e5995828ace0a73da10cc1f105880433be7 Mon Sep 17 00:00:00 2001 From: Rotimi Best Date: Sat, 15 Jun 2024 09:23:02 +0100 Subject: [PATCH] chore: reuse getSubdomain function --- apps/dashboard/src/routes/+layout.server.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/dashboard/src/routes/+layout.server.ts b/apps/dashboard/src/routes/+layout.server.ts index 1f143521..111fe4fd 100644 --- a/apps/dashboard/src/routes/+layout.server.ts +++ b/apps/dashboard/src/routes/+layout.server.ts @@ -60,8 +60,7 @@ export const load = async ({ url, cookies }): Promise => { const debugPlay = cookies.get('debugPlay'); const debugMode = _orgSiteName && _orgSiteName !== 'false'; - const matches = url.host.match(/([a-z 0-9 -]+).*classroomio[.]com/); - const subdomain = matches?.[1] ?? ''; + const subdomain = getSubdomain(url) || ''; const isDev = dev || isLocalHost; @@ -71,7 +70,7 @@ export const load = async ({ url, cookies }): Promise => { } if (!blockedSubdomain.includes(subdomain)) { - const answer = Array.isArray(matches) ? !!subdomain && subdomain !== 'www' : false; + const answer = !!subdomain; response.isOrgSite = debugMode || answer; response.orgSiteName = debugMode ? _orgSiteName : subdomain; @@ -111,9 +110,12 @@ function getInitialLocale(): string { } function getSubdomain(url: URL) { - const parts = url.host.split('.'); - if (url.host.endsWith(PRIVATE_APP_HOST)) { + const host = url.host.replace('www.', ''); + const parts = host.split('.'); + + if (host.endsWith(PRIVATE_APP_HOST)) { return parts.length >= 3 ? parts[0] : null; } + return null; }