Nextjs-Cors is a node.js package to provide a middleware that can be used to enable CORS with various options in nextjs applications.
npm install nextjs-corsCORS middleware for Next.js API routes.




``bash`
npm install nextjs-corsor
yarn add nextjs-corsor
pnpm add nextjs-cors
`ts
import NextCors from "nextjs-cors";
export default async function handler(req, res) {
// Run CORS middleware
await NextCors(req, res, {
methods: ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE"],
origin: "*",
optionsSuccessStatus: 200,
});
// Your API logic
res.json({ message: "Hello NextJs Cors!" });
}
``
This package uses the cors package. See the cors documentation for all available options.