2025-08-05 17:40:31 +01:00
|
|
|
import { getSupabase, supabase } from '$lib/utils/functions/supabase';
|
2025-05-03 14:46:01 +01:00
|
|
|
|
2025-08-05 17:40:31 +01:00
|
|
|
import type { CurrentOrg } from '$lib/utils/types/org';
|
|
|
|
|
import type { MetaTagsProps } from 'svelte-meta-tags';
|
2025-10-11 13:27:50 +01:00
|
|
|
import { PUBLIC_IS_SELFHOSTED } from '$env/static/public';
|
2025-08-05 17:40:31 +01:00
|
|
|
import { blockedSubdomain } from '$lib/utils/constants/app';
|
2024-12-28 23:11:55 +01:00
|
|
|
import { dev } from '$app/environment';
|
2024-10-09 15:00:30 +01:00
|
|
|
import { env } from '$env/dynamic/private';
|
2024-12-28 23:11:55 +01:00
|
|
|
import { getCurrentOrg } from '$lib/utils/services/org';
|
|
|
|
|
import { redirect } from '@sveltejs/kit';
|
2023-08-21 10:10:11 +01:00
|
|
|
|
|
|
|
|
if (!supabase) {
|
|
|
|
|
getSupabase();
|
|
|
|
|
}
|
2023-08-14 06:22:03 +01:00
|
|
|
|
2025-09-07 10:24:34 +01:00
|
|
|
export const ssr = PUBLIC_IS_SELFHOSTED === 'true' ? false : true;
|
2025-05-03 14:46:01 +01:00
|
|
|
|
2023-10-29 12:07:34 +00:00
|
|
|
interface LoadOutput {
|
|
|
|
|
orgSiteName: string;
|
|
|
|
|
isOrgSite: boolean;
|
|
|
|
|
skipAuth: boolean;
|
2023-12-03 16:29:27 +03:00
|
|
|
org: CurrentOrg | null;
|
2024-08-01 14:04:50 +01:00
|
|
|
baseMetaTags: MetaTagsProps;
|
2024-12-28 23:11:55 +01:00
|
|
|
serverLang: string;
|
2023-10-29 12:07:34 +00:00
|
|
|
}
|
|
|
|
|
|
2025-08-26 16:46:01 +01:00
|
|
|
const APP_SUBDOMAINS = env.PRIVATE_APP_SUBDOMAINS?.split(',') || [];
|
2025-01-06 03:36:00 +01:00
|
|
|
|
2024-12-28 23:11:55 +01:00
|
|
|
export const load = async ({ url, cookies, request }): Promise<LoadOutput> => {
|
2023-12-03 16:29:27 +03:00
|
|
|
const response: LoadOutput = {
|
2023-08-14 06:22:03 +01:00
|
|
|
orgSiteName: '',
|
|
|
|
|
isOrgSite: false,
|
2023-08-20 19:08:48 +00:00
|
|
|
skipAuth: false,
|
2024-08-01 14:04:50 +01:00
|
|
|
org: null,
|
2024-12-28 23:11:55 +01:00
|
|
|
baseMetaTags: getBaseMetaTags(url),
|
|
|
|
|
serverLang: request.headers?.get('accept-language') || ''
|
2023-08-14 06:22:03 +01:00
|
|
|
};
|
|
|
|
|
|
2025-09-07 10:24:34 +01:00
|
|
|
console.log('PUBLIC_IS_SELFHOSTED', PUBLIC_IS_SELFHOSTED);
|
2025-01-06 03:36:00 +01:00
|
|
|
|
2024-06-15 08:55:46 +01:00
|
|
|
// Selfhosted usecase would be here
|
2025-09-07 10:24:34 +01:00
|
|
|
if (PUBLIC_IS_SELFHOSTED === 'true') {
|
2024-06-15 08:55:46 +01:00
|
|
|
const subdomain = getSubdomain(url);
|
2024-10-09 14:51:32 +01:00
|
|
|
console.log('subdomain', subdomain);
|
2024-06-15 08:55:46 +01:00
|
|
|
|
|
|
|
|
// Student dashboard
|
|
|
|
|
if (subdomain) {
|
|
|
|
|
const org = (await getCurrentOrg(subdomain, true)) || null;
|
|
|
|
|
|
|
|
|
|
// Organization by subdomain not found
|
|
|
|
|
if (!org) {
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response.org = org;
|
|
|
|
|
response.isOrgSite = true;
|
|
|
|
|
response.orgSiteName = subdomain;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-05 17:40:31 +01:00
|
|
|
// Never go beyond this for selfhosted instances
|
2024-06-15 08:55:46 +01:00
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-25 07:22:46 +01:00
|
|
|
const isLocalHost = url.host.includes('localhost');
|
|
|
|
|
|
|
|
|
|
const tempSiteName = url.searchParams.get('org');
|
|
|
|
|
|
|
|
|
|
if (isLocalHost && tempSiteName) {
|
|
|
|
|
console.log('setting sitename temp');
|
2024-06-16 05:01:35 +01:00
|
|
|
cookies.set('_orgSiteName', tempSiteName, {
|
|
|
|
|
path: '/'
|
|
|
|
|
});
|
2024-04-25 07:22:46 +01:00
|
|
|
}
|
|
|
|
|
|
2023-08-24 07:32:19 +00:00
|
|
|
const _orgSiteName = cookies.get('_orgSiteName');
|
2023-08-14 06:22:03 +01:00
|
|
|
const debugPlay = cookies.get('debugPlay');
|
2023-08-24 15:58:08 +01:00
|
|
|
const debugMode = _orgSiteName && _orgSiteName !== 'false';
|
2023-08-14 06:22:03 +01:00
|
|
|
|
2024-06-15 09:23:02 +01:00
|
|
|
const subdomain = getSubdomain(url) || '';
|
2023-08-14 06:22:03 +01:00
|
|
|
|
2024-04-25 07:22:46 +01:00
|
|
|
const isDev = dev || isLocalHost;
|
2024-04-20 04:39:16 +01:00
|
|
|
|
2025-01-06 03:36:00 +01:00
|
|
|
if (isURLCustomDomain(url)) {
|
2024-09-04 06:32:54 +01:00
|
|
|
// Custom domain
|
|
|
|
|
response.org = (await getCurrentOrg(url.host, true, true)) || null;
|
2024-02-02 08:25:15 +01:00
|
|
|
|
2024-09-04 06:32:54 +01:00
|
|
|
console.log('custom domain response.org', response.org);
|
|
|
|
|
|
|
|
|
|
if (!response.org) {
|
2025-09-07 10:24:34 +01:00
|
|
|
console.error('Custom domain org not found, loading dashboard');
|
|
|
|
|
return response;
|
2024-09-04 06:32:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response.isOrgSite = true;
|
|
|
|
|
response.orgSiteName = response.org?.siteName || '';
|
|
|
|
|
return response;
|
|
|
|
|
} else if (!blockedSubdomain.includes(subdomain)) {
|
2025-01-06 03:36:00 +01:00
|
|
|
if (APP_SUBDOMAINS.includes(subdomain)) {
|
|
|
|
|
// This is an app domain specified in the .env file
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('subdomain', subdomain);
|
|
|
|
|
|
2025-11-08 05:22:38 +01:00
|
|
|
response.isOrgSite = debugMode || !!subdomain;
|
2023-08-24 07:32:19 +00:00
|
|
|
response.orgSiteName = debugMode ? _orgSiteName : subdomain;
|
2023-12-03 16:29:27 +03:00
|
|
|
response.org = (await getCurrentOrg(response.orgSiteName, true)) || null;
|
2023-12-11 03:27:13 +03:00
|
|
|
|
2024-04-20 04:39:16 +01:00
|
|
|
if (!response.org && !isDev) {
|
2023-12-14 22:41:16 +03:00
|
|
|
throw redirect(307, 'https://app.classroomio.com/404?type=org');
|
2024-04-25 07:22:46 +01:00
|
|
|
} else if (!response.org && _orgSiteName) {
|
2025-05-03 14:46:01 +01:00
|
|
|
cookies.delete('_orgSiteName', { path: '/' });
|
2023-12-11 03:27:13 +03:00
|
|
|
}
|
2023-08-14 06:22:03 +01:00
|
|
|
} else if (subdomain === 'play' || debugPlay === 'true') {
|
|
|
|
|
response.skipAuth = true;
|
2025-01-06 03:36:00 +01:00
|
|
|
} else if (!APP_SUBDOMAINS.includes(subdomain) && !isDev) {
|
2024-06-15 08:55:46 +01:00
|
|
|
// This case is for anything in our blockedSubdomains
|
2023-12-14 22:41:16 +03:00
|
|
|
throw redirect(307, 'https://app.classroomio.com');
|
2023-08-14 06:22:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response;
|
|
|
|
|
};
|
2024-04-19 05:45:48 +01:00
|
|
|
|
2025-01-06 03:36:00 +01:00
|
|
|
function isURLCustomDomain(url: URL) {
|
|
|
|
|
if (url.host.includes('localhost')) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const notCustomDomainHosts = [env.PRIVATE_APP_HOST || '', 'classroomio.com', 'vercel.app'].filter(
|
|
|
|
|
Boolean
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return !notCustomDomainHosts.some((host) => url.host.endsWith(host));
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-01 14:04:50 +01:00
|
|
|
function getBaseMetaTags(url: URL) {
|
|
|
|
|
return Object.freeze({
|
2024-10-07 01:36:07 +01:00
|
|
|
title: 'ClassroomIO | The Open Source Learning Management System for Companies',
|
2024-08-01 14:04:50 +01:00
|
|
|
description:
|
2024-10-07 01:36:07 +01:00
|
|
|
'A flexible, user-friendly platform for creating, managing, and delivering courses for companies and training organisations',
|
2024-08-01 14:04:50 +01:00
|
|
|
canonical: new URL(url.pathname, url.origin).href,
|
|
|
|
|
openGraph: {
|
|
|
|
|
type: 'website',
|
|
|
|
|
url: new URL(url.pathname, url.origin).href,
|
|
|
|
|
locale: 'en_IE',
|
2024-10-07 01:36:07 +01:00
|
|
|
title: 'ClassroomIO | The Open Source Learning Management System for Companies',
|
2024-08-01 14:04:50 +01:00
|
|
|
description:
|
2024-10-07 01:36:07 +01:00
|
|
|
'A flexible, user-friendly platform for creating, managing, and delivering courses for companies and training organisations',
|
2024-08-01 14:04:50 +01:00
|
|
|
siteName: 'ClassroomIO',
|
|
|
|
|
images: [
|
|
|
|
|
{
|
2024-09-05 15:51:05 +01:00
|
|
|
url: 'https://brand.cdn.clsrio.com/og/classroomio-og.png',
|
2024-08-01 14:04:50 +01:00
|
|
|
alt: 'ClassroomIO OG Image',
|
|
|
|
|
width: 1920,
|
|
|
|
|
height: 1080,
|
2024-09-05 15:51:05 +01:00
|
|
|
secureUrl: 'https://brand.cdn.clsrio.com/og/classroomio-og.png',
|
2024-08-01 14:04:50 +01:00
|
|
|
type: 'image/jpeg'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
twitter: {
|
|
|
|
|
handle: '@classroomio',
|
|
|
|
|
site: '@classroomio',
|
2024-08-25 21:35:59 +01:00
|
|
|
cardType: 'summary_large_image' as const,
|
2024-10-07 01:36:07 +01:00
|
|
|
title: 'ClassroomIO | The Open Source Learning Management System for Companies',
|
2024-08-01 14:04:50 +01:00
|
|
|
description:
|
2024-10-07 01:36:07 +01:00
|
|
|
'A flexible, user-friendly platform for creating, managing, and delivering courses for companies and training organisations',
|
2024-09-05 15:51:05 +01:00
|
|
|
image: 'https://brand.cdn.clsrio.com/og/classroomio-og.png',
|
2024-08-01 14:04:50 +01:00
|
|
|
imageAlt: 'ClassroomIO OG Image'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-15 08:55:46 +01:00
|
|
|
function getSubdomain(url: URL) {
|
2025-11-08 05:22:38 +01:00
|
|
|
console.log('url.host', url);
|
2024-06-15 09:23:02 +01:00
|
|
|
const host = url.host.replace('www.', '');
|
2025-11-08 05:22:38 +01:00
|
|
|
console.log('host', host);
|
2025-05-03 14:46:01 +01:00
|
|
|
const parts = host?.split('.');
|
2025-11-08 05:22:38 +01:00
|
|
|
console.log('parts', parts);
|
2024-06-15 09:23:02 +01:00
|
|
|
|
2025-05-03 14:46:01 +01:00
|
|
|
if (host?.endsWith(env.PRIVATE_APP_HOST)) {
|
2025-11-08 05:22:38 +01:00
|
|
|
console.log('is app host');
|
2025-05-03 14:46:01 +01:00
|
|
|
return parts?.length >= 3 ? parts[0] : null;
|
2024-06-15 08:55:46 +01:00
|
|
|
}
|
2024-06-15 09:23:02 +01:00
|
|
|
|
2024-06-15 08:55:46 +01:00
|
|
|
return null;
|
|
|
|
|
}
|