import { next } from '@vercel/functions'; export const config = { runtime: 'nodejs', matcher: '/' }; export default function middleware(request) { const url = new URL(request.url); // X already registers the site root. Intercept only complete OAuth returns // before the static homepage/cache; ordinary page visits remain static. if (url.pathname === '/' && url.searchParams.has('state') && (url.searchParams.has('code') || url.searchParams.has('error'))) { const destination = new URL('https://inkspring.ai/api/connect'); destination.searchParams.set('action', 'callback'); destination.searchParams.set('provider', 'x'); for (const key of ['state', 'code', 'error']) if (url.searchParams.has(key)) destination.searchParams.set(key, url.searchParams.get(key)); return new Response(null, { status: 302, headers: { Location: destination.href, 'Cache-Control': 'no-store', 'Referrer-Policy': 'no-referrer' } }); } return next(); }