nextjs cors
v2.2.0
Nextjs-Cors -это пакет Node.js для предоставления промежуточного программного обеспечения, которое можно использовать для включения CORS с различными опциями в приложениях NextJS.
Сначала нам придется установить, чтобы использовать этот замечательный пакет.
# Using npm
npm install nextjs-cors@latest
# Using yarn
yarn add nextjs-cors@latest
# Using pnpm
pnpm add nextjs-cors@latestNextJs-Cors использует пакет CORS, поэтому мы приглашаем вас проверить документацию https://github.com/expressjs/cors
Страницы/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 по лицензии.