moshing-mammut/src/hooks.server.ts

33 lines
1007 B
TypeScript
Raw Normal View History

2023-04-02 15:41:33 +00:00
import { TimelineReader } from '$lib/server/timeline';
import type { HandleServerError } from '@sveltejs/kit';
2023-04-05 14:21:43 +00:00
import fs from 'fs/promises';
2023-04-02 15:41:33 +00:00
TimelineReader.init();
export const handleError = (({ error }) => {
if (error instanceof Error) {
console.error('Something went wrong: ', error.name, error.message);
}
return {
message: 'Whoops!',
code: (error as any)?.code ?? 'UNKNOWN'
};
2023-04-05 14:21:43 +00:00
}) satisfies HandleServerError;
import type { Handle } from '@sveltejs/kit';
export const handle = (async ({ event, resolve }) => {
// Reeder *insists* on checking /feed instead of /feed.xml
if (event.url.pathname === '/feed') {
return new Response('', { status: 301, headers: { Location: '/feed.xml' } });
}
if (event.url.pathname === '/feed.xml') {
const f = await fs.readFile('feed.xml', { encoding: 'utf8' });
2023-04-11 14:02:54 +00:00
return new Response(f, { headers: [['Content-Type', 'application/atom+xml']] });
2023-04-05 14:21:43 +00:00
}
const response = await resolve(event);
return response;
2023-04-11 14:02:54 +00:00
}) satisfies Handle;