nextjs cors
v2.2.0
Nextjs-Cors ist ein Node.js-Paket, mit dem eine Middleware verwendet werden kann, mit der CORs mit verschiedenen Optionen in NextJS-Anwendungen ermöglicht werden können.
Zuerst müssen wir installieren, um dieses wunderbare Paket zu verwenden.
# Using npm
npm install nextjs-cors@latest
# Using yarn
yarn add nextjs-cors@latest
# Using pnpm
pnpm add nextjs-cors@latestNextJS-Cors verwendet das CORS
Seiten/api/whoami. {ts, js}
import NextCors from 'nextjs-cors' ;
async function handler ( req , res ) {
// Run the cors middleware
// nextjs-cors uses the cors package, so we invite you to check the documentation https://github.com/expressjs/cors
await NextCors ( req , res , {
// Options
methods : [ 'GET' , 'HEAD' , 'PUT' , 'PATCH' , 'POST' , 'DELETE' ] ,
origin : '*' ,
optionsSuccessStatus : 200 , // some legacy browsers (IE11, various SmartTVs) choke on 204
} ) ;
// Rest of the API logic
res . json ( { message : 'Hello NextJs Cors!' } ) ;
} nextjs-cors unter Lizenz.