Files
classroomio/apps/dashboard/src/routes/+layout.server.ts
T
35f5216839 fix(org): favicon fallback, OG logo styling, and Discord embed CDN URLs (#714)
* fix(org): serve OG images from CDN for Discord embeds

Discord times out on slow dynamic OG generation (~3-5s). Persist generated
images to R2, point meta tags at the media CDN, and warm the API endpoint
on org-site page loads so crawlers get a fast static PNG URL.

Co-authored-by: Rotimi Best <rotimi-best@users.noreply.github.com>

* docs: add org-site Open Graph and favicon guides

Document user-facing sharing behavior and contributor architecture
for dynamic OG images, favicon fallback, R2/CDN caching, and embed
cache invalidation.

Co-authored-by: Rotimi Best <rotimi-best@users.noreply.github.com>

* fix(org-site): address PR review on OG CDN fallback and docs

- Fall back to API OG URL when CDN object is not yet available (HEAD check)
- Cancel warm-fetch response body to avoid connection pool exhaustion
- Align tenant-router OG edge cache TTL with one-hour API revalidation
- Fix favicon docs navigation and add Custom Domain tab screenshot
- Replace Chiberry Artistry example with AI Academy

Co-authored-by: Rotimi Best <rotimi-best@users.noreply.github.com>

* fix(org-site): accept docker hostnames for OG warm URL

Use isValidHttpUrl for PRIVATE_SERVER_URL so internal values like
http://api:3081 work for SSR warm fetches in Docker Compose.

Co-authored-by: Rotimi Best <rotimi-best@users.noreply.github.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Rotimi Best <rotimi-best@users.noreply.github.com>
2026-07-09 13:38:49 +01:00

73 lines
2.6 KiB
TypeScript

import type { AccountOrg } from '$features/app/types';
import type { MetaTagsProps } from 'svelte-meta-tags';
import type { UploadLimits } from '$lib/utils/config/upload-limits';
import { PUBLIC_IS_SELFHOSTED } from '$env/static/public';
import { env } from '$env/dynamic/private';
import { env as publicEnv } from '$env/dynamic/public';
import { getBaseMetaTags } from '$lib/utils/functions/metaTags.server';
import { getOrgSiteInfo } from '$features/app/layout-setup';
import { getUploadLimits } from '$lib/utils/config/upload-limits';
import { resolveOrgSiteOgWarmUrl } from '$lib/utils/functions/org-site-og-url';
export const ssr = true;
interface LoadOutput {
orgSiteName: string;
isOrgSite: boolean;
skipAuth: boolean;
org: AccountOrg | null;
baseMetaTags: MetaTagsProps;
serverLang: string;
localeCookie: string;
locals: App.Locals;
uploadLimits: UploadLimits;
}
export const load = async ({ url, cookies, request, locals }): Promise<LoadOutput> => {
const loadStart = performance.now();
const debugPlay = cookies.get('debugPlay');
const orgSiteInfoStart = performance.now();
const orgSiteInfo = await getOrgSiteInfo(url, cookies);
const orgSiteInfoMs = Math.round((performance.now() - orgSiteInfoStart) * 100) / 100;
if (orgSiteInfo.isOrgSite && orgSiteInfo.org?.siteName) {
const warmUrl = resolveOrgSiteOgWarmUrl({
siteName: orgSiteInfo.org.siteName,
isSelfHosted: PUBLIC_IS_SELFHOSTED === 'true',
privateServerUrl: env.PRIVATE_SERVER_URL,
publicServerUrl: publicEnv.PUBLIC_SERVER_URL
});
if (warmUrl) {
void fetch(warmUrl)
.then((response) => response.body?.cancel())
.catch(() => {});
}
}
const response: LoadOutput = {
orgSiteName: orgSiteInfo.orgSiteName,
isOrgSite: orgSiteInfo.isOrgSite,
skipAuth: orgSiteInfo.subdomain === 'play' || debugPlay === 'true',
org: orgSiteInfo.org,
baseMetaTags: await getBaseMetaTags(url, orgSiteInfo),
serverLang: request.headers?.get('accept-language') || '',
localeCookie: cookies.get('classroomio_locale') || '',
locals,
uploadLimits: getUploadLimits()
};
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.
// if (!APP_SUBDOMAINS.includes(orgSiteInfo.subdomain) && !dev && !orgSiteInfo.isOrgSite) {
// redirect(307, 'https://app.classroomio.com');
// }
return response;
};