Skip to content

Commit 98f8265

Browse files
authored
fix(chat): dynamically resolve base domains for subdomain link rendering (#493)
1 parent 0e8109e commit 98f8265

1 file changed

Lines changed: 35 additions & 22 deletions

File tree

‎resources/js/pages/Chat/Index.vue‎

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,50 +1255,63 @@ const submitReport = async () => {
12551255
}
12561256
};
12571257
1258+
const getBaseDomain = (hostname: string): string => {
1259+
const cleanHost = hostname.split(':')[0].toLowerCase();
1260+
1261+
if (
1262+
!cleanHost ||
1263+
cleanHost === 'localhost' ||
1264+
/^(\d{1,3}\.){3}\d{1,3}$/.test(cleanHost)
1265+
) {
1266+
return cleanHost;
1267+
}
1268+
1269+
const parts = cleanHost.split('.');
1270+
1271+
if (parts.length <= 2) {
1272+
return cleanHost;
1273+
}
1274+
1275+
return parts.slice(-2).join('.');
1276+
};
1277+
12581278
const isPlatformUrl = (urlString: string): boolean => {
12591279
if (urlString.startsWith('/')) {
12601280
return true;
12611281
}
12621282
12631283
try {
12641284
const parsed = new URL(urlString);
1265-
const validHosts = new Set<string>();
1266-
1267-
if (typeof window !== 'undefined') {
1268-
if (window.location.hostname) {
1269-
validHosts.add(window.location.hostname.toLowerCase());
1270-
}
1285+
const parsedHostname = parsed.hostname.toLowerCase();
1286+
const baseDomains = new Set<string>();
12711287
1272-
if (window.location.host) {
1273-
validHosts.add(window.location.host.toLowerCase());
1274-
}
1288+
if (typeof window !== 'undefined' && window.location.hostname) {
1289+
const currentHost = window.location.hostname.toLowerCase();
1290+
baseDomains.add(currentHost);
1291+
baseDomains.add(getBaseDomain(currentHost));
12751292
}
12761293
12771294
const envAppUrl = import.meta.env.VITE_APP_URL;
12781295
12791296
if (envAppUrl) {
12801297
try {
12811298
const appParsed = new URL(envAppUrl);
1282-
validHosts.add(appParsed.hostname.toLowerCase());
1283-
validHosts.add(appParsed.host.toLowerCase());
1299+
const envHost = appParsed.hostname.toLowerCase();
1300+
baseDomains.add(envHost);
1301+
baseDomains.add(getBaseDomain(envHost));
12841302
} catch {
12851303
// ignore
12861304
}
12871305
}
12881306
1289-
validHosts.add('hscstack.com');
1290-
validHosts.add('www.hscstack.com');
1291-
1292-
const parsedHostname = parsed.hostname.toLowerCase();
1293-
const parsedHost = parsed.host.toLowerCase();
1294-
1295-
for (const host of validHosts) {
1296-
const cleanHost = host.split(':')[0];
1307+
for (const base of baseDomains) {
1308+
if (!base) {
1309+
continue;
1310+
}
12971311
12981312
if (
1299-
parsedHostname === cleanHost ||
1300-
parsedHost === host ||
1301-
parsedHostname.endsWith(`.${cleanHost}`)
1313+
parsedHostname === base ||
1314+
parsedHostname.endsWith(`.${base}`)
13021315
) {
13031316
return true;
13041317
}

0 commit comments

Comments
 (0)