Content Negotiation with Accept header
import { createNegotiation } from "sveltekit-negotiate";
export const { handle, reroute, negotiate, Negotiate } = createNegotiation({
"text/markdown": { extension: ".md" },
"application/json": { extension: ".json" },
});
import { negotiate } from "$lib/negotiate";
export const load = async ({ locals }) => {
const message = "Hello, content negotiation!";
return {
message,
...negotiate(locals, {
"text/markdown": () => `# ${message}`,
}),
};
};
<script lang="ts">
let { data } = $props();
</script>
<section data-role="content">
<h1 class="text-2xl font-bold">{data.message}</h1>
</section>
import { definePageMetaTags } from "svelte-meta-tags";
export const load = async ({ parent, data }) => {
await parent();
const { pageMetaTags } = definePageMetaTags({
title: "Negotiate",
});
return { ...data, pageMetaTags };
};
import {
POCKETBASE_URL,
POCKETBASE_SUPERUSER_EMAIL,
POCKETBASE_SUPERUSER_PASSWORD,
} from "$env/static/private";
import { sequence } from "@sveltejs/kit/hooks";
import { handlePocketbase } from "@velastack/pocketbase";
import { handle as handleNegotiate } from "$lib/negotiate";
export const handle = sequence(
handleNegotiate,
handlePocketbase({
pocketbaseUrl: POCKETBASE_URL,
superuserEmail: POCKETBASE_SUPERUSER_EMAIL,
superuserPassword: POCKETBASE_SUPERUSER_PASSWORD,
}),
);
import { reroute as negotiateReroute } from "$lib/negotiate";
export const reroute = ({ url }) => negotiateReroute(url.pathname);