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

51 lines
1.7 KiB
TypeScript
Raw Normal View History

import type { AccountOrg } from '$features/app/types';
import type { MetaTagsProps } from 'svelte-meta-tags';
import { PUBLIC_IS_SELFHOSTED } from '$env/static/public';
2026-03-09 11:18:22 +01:00
import { getBaseMetaTags } from '$lib/utils/functions/metaTags';
2026-03-11 12:01:26 +01:00
import { getOrgSiteInfo } from '$features/app/layout-setup';
2023-08-14 06:22:03 +01:00
2026-03-11 12:01:26 +01:00
export const ssr = 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;
org: AccountOrg | null;
2024-08-01 14:04:50 +01:00
baseMetaTags: MetaTagsProps;
serverLang: string;
2026-03-09 11:18:22 +01:00
localeCookie: string;
locals: App.Locals;
2023-10-29 12:07:34 +00:00
}
export const load = async ({ url, cookies, request, locals }): Promise<LoadOutput> => {
2026-03-09 11:18:22 +01:00
const loadStart = performance.now();
const debugPlay = cookies.get('debugPlay');
2026-03-09 11:18:22 +01:00
const orgSiteInfoStart = performance.now();
const orgSiteInfo = await getOrgSiteInfo(url, cookies);
2026-03-09 11:18:22 +01:00
const orgSiteInfoMs = Math.round((performance.now() - orgSiteInfoStart) * 100) / 100;
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,
2026-03-09 11:18:22 +01:00
baseMetaTags: getBaseMetaTags(url, orgSiteInfo),
serverLang: request.headers?.get('accept-language') || '',
2026-03-09 11:18:22 +01:00
localeCookie: cookies.get('classroomio_locale') || '',
locals
2023-08-14 06:22:03 +01:00
};
2026-03-09 11:18:22 +01:00
const loadMs = Math.round((performance.now() - loadStart) * 100) / 100;
console.log(
`[+layout.server] load: ${loadMs}ms (getOrgSiteInfo: ${orgSiteInfoMs}ms) | PUBLIC_IS_SELFHOSTED=${PUBLIC_IS_SELFHOSTED}`
);
// If it isn't a registered dashboard domain and also not a valid sub domain.
2026-03-09 11:18:22 +01:00
// if (!APP_SUBDOMAINS.includes(orgSiteInfo.subdomain) && !dev && !orgSiteInfo.isOrgSite) {
// redirect(307, 'https://app.classroomio.com');
// }
2023-08-14 06:22:03 +01:00
return response;
};