Back to Next Js

API Routes Example with CORS

examples/api-routes-cors/README.md

16.2.51.3 KB
Original Source

API Routes Example with CORS

Next.js ships with API routes which provides an easy solution to build your own API.

This example shows how to create an API endpoint with CORS headers, using the cors package.

Deploy your own

How to use

Execute create-next-app with npm, Yarn, or pnpm to bootstrap the example:

bash
npx create-next-app --example api-routes-cors api-routes-cors-app
bash
yarn create next-app --example api-routes-cors api-routes-cors-app
bash
pnpm create next-app --example api-routes-cors api-routes-cors-app

Deploy it to the cloud with Vercel (Documentation).