Files
classroomio/apps/dashboard/src/routes/+layout.server.ts
T

91 lines
3.1 KiB
TypeScript
Raw Normal View History

import { getSupabase, supabase } from '$lib/utils/functions/supabase';
2025-05-03 14:46:01 +01:00
import type { AccountOrg } from '$features/app/types';
import type { MetaTagsProps } from 'svelte-meta-tags';
import { PUBLIC_IS_SELFHOSTED } from '$env/static/public';
import { dev } from '$app/environment';
2024-10-09 15:00:30 +01:00
import { env } from '$env/dynamic/private';
import { getOrgSiteInfo } from '$features/app/layout-setup';
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
const APP_SUBDOMAINS = env.PRIVATE_APP_SUBDOMAINS?.split(',') || [];
2023-10-29 12:07:34 +00:00
interface LoadOutput {
orgSiteName: string;
isOrgSite: boolean;
skipAuth: boolean;
org: AccountOrg | null;
2024-08-01 14:04:50 +01:00
baseMetaTags: MetaTagsProps;
serverLang: string;
locals: App.Locals;
2023-10-29 12:07:34 +00:00
}
export const load = async ({ url, cookies, request, locals }): Promise<LoadOutput> => {
const debugPlay = cookies.get('debugPlay');
const orgSiteInfo = await getOrgSiteInfo(url, cookies);
2023-12-03 16:29:27 +03:00
const response: LoadOutput = {
orgSiteName: orgSiteInfo.orgSiteName,
isOrgSite: orgSiteInfo.isOrgSite,
skipAuth: orgSiteInfo.subdomain === 'play' || debugPlay === 'true',
org: orgSiteInfo.org,
baseMetaTags: getBaseMetaTags(url),
serverLang: request.headers?.get('accept-language') || '',
locals
2023-08-14 06:22:03 +01:00
};
2025-09-07 10:24:34 +01:00
console.log('PUBLIC_IS_SELFHOSTED', PUBLIC_IS_SELFHOSTED);
// If it isn't a registered dashboard domain and also not a valid sub domain.
if (!APP_SUBDOMAINS.includes(orgSiteInfo.subdomain) && !dev && !orgSiteInfo.isOrgSite) {
2025-11-01 15:49:29 +01:00
redirect(307, 'https://app.classroomio.com');
2023-08-14 06:22:03 +01:00
}
return response;
};
2024-04-19 05:45:48 +01:00
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'
}
});
}