You should be using Next.js Edge API Routes + middleware instead of the functions directory - Cloudflare Developers