import { NextResponse } from 'next/server'; /** The Chromium extension calls these routes from a background service worker, * whose Origin is `chrome-extension://`. The id changes every time the * unpacked extension is reloaded, so we allow any origin — these routes are * only ever reachable on the LAN behind the port-3000 firewall rule. */ export const CORS_HEADERS = { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET, POST, PATCH, DELETE, OPTIONS', 'Access-Control-Allow-Headers': 'Content-Type', } as const; export function corsJson(body: unknown, init?: { status?: number }) { return NextResponse.json(body, { status: init?.status ?? 200, headers: CORS_HEADERS }); } export function corsPreflight() { return new NextResponse(null, { status: 204, headers: CORS_HEADERS }); }