Files
windwiderstand/src/hooks.server.ts
T
Peter Meier 2fef91a548
Deploy / verify (push) Failing after 32s
Deploy / deploy (push) Has been skipped
Initial SvelteKit frontend port of windwiderstand.de
Full parity with Astro site: content rows, post/tag routes, pagination,
event badges + OSM map, comments, Live-Search via /api/search-index,
CMS image proxy, RSS, sitemap.

Deploy: Dockerfile + docker-compose.prod.yml + Gitea Actions workflow
to build + push to git.pm86.de registry and ssh-deploy to Contabo.
2026-04-17 22:01:30 +02:00

54 lines
1.7 KiB
TypeScript

import { getTranslationBundleBySlug } from '$lib/cms';
import { TRANSLATION_BUNDLE_SLUG } from '$lib/constants';
import type { Handle } from '@sveltejs/kit';
/**
* Page-Routen: kurze Edge-Cache + SWR. Webhook purged App-Cache,
* Edge läuft via stale-while-revalidate auf den warmen App-Cache.
*/
const PAGE_CACHE_CONTROL =
'public, max-age=0, s-maxage=30, stale-while-revalidate=300';
function isCacheablePath(pathname: string): boolean {
if (pathname.startsWith('/api/')) return false;
if (pathname.startsWith('/cms-images/')) return false;
if (pathname.startsWith('/_app/')) return false;
return true;
}
export const handle: Handle = async ({ event, resolve }) => {
try {
const bundle = await getTranslationBundleBySlug(TRANSLATION_BUNDLE_SLUG, { locale: 'de' });
if (bundle?.strings && typeof bundle.strings === 'object') {
const normalized: Record<string, string> = {};
for (const [key, val] of Object.entries(bundle.strings)) {
const v = val as unknown;
const str =
typeof v === 'string'
? v
: typeof v === 'object' && v !== null && 'value' in v
? (v as { value?: unknown }).value
: (v as { text?: unknown })?.text ?? (v as { label?: unknown })?.label;
if (typeof str === 'string') normalized[key] = str;
}
event.locals.translations = normalized;
} else {
event.locals.translations = {};
}
} catch {
event.locals.translations = {};
}
const response = await resolve(event);
if (
event.request.method === 'GET' &&
isCacheablePath(event.url.pathname) &&
!response.headers.has('cache-control')
) {
response.headers.set('cache-control', PAGE_CACHE_CONTROL);
}
return response;
};