import type { Handle } from "@sveltejs/kit";

export const handle: Handle = async ({ event, resolve }) => {
	const response = await resolve(event);

	// https://sqlocal.dev/guide/setup#cross-origin-isolation
	// Cross-origin isolation (needed for SharedArrayBuffer/Atomics -> sqlite-wasm OPFS)
	response.headers.set("Cross-Origin-Opener-Policy", "same-origin");
	response.headers.set("Cross-Origin-Embedder-Policy", "require-corp");

	// Optional, but commonly paired
	response.headers.set("Cross-Origin-Resource-Policy", "same-origin");

	return response;
};
