{"library":"nextjs-cors","title":"nextjs-cors","description":"CORS middleware for Next.js API routes, built on top of the popular Express cors package. Current stable version is 2.2.1, released as a patch update preparing for the next major version. Provides a simple, drop-in solution to enable Cross-Origin Resource Sharing in Next.js API routes with all standard cors options (methods, origin, allowed headers, etc.). Uses an async middleware pattern that fits naturally into Next.js API route handlers. Unlike generic cors packages, nextjs-cors is specifically designed for Next.js's request/response model and does not require wrapping or additional configuration to work with Edge Runtime (though support depends on underlying cors). Ships TypeScript definitions, making it easy to use in TS projects. Peer dependency on Next.js >=8.1.1-canary.54, ensuring compatibility with older versions. Compared to other Next.js CORS solutions like next-connect or manual headers, nextjs-cors offers a minimal API and leverages the well-tested cors package.","language":"javascript","status":"active","last_verified":"Sat Apr 25","install":{"commands":["npm install nextjs-cors"],"cli":null},"imports":["import NextCors from 'nextjs-cors'","import NextCors from 'nextjs-cors'","const NextCors = require('nextjs-cors').default"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import NextCors from 'nextjs-cors';\nimport type { NextApiRequest, NextApiResponse } from 'next';\n\nexport default async function handler(\n  req: NextApiRequest,\n  res: NextApiResponse\n) {\n  await NextCors(req, res, {\n    methods: ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE'],\n    origin: '*',\n    optionsSuccessStatus: 200,\n  });\n\n  res.json({ message: 'Hello NextJs Cors!' });\n}","lang":"typescript","description":"Demonstrates how to use nextjs-cors as middleware in a Next.js API route with CORS options.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}