Download next.js/examples/api-routes-middleware/pages/api/cookies.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 482 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/examples/api-routes-middleware/pages/api/cookies.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/examples/api-routes-middleware/pages/api/cookies.ts
-
curl -L -o cookies.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/examples/api-routes-middleware/pages/api/cookies.ts
482 Bytes
| import type { NextApiRequest, NextApiResponse } from "next"; | |
| import { setCookie } from "../../utils/cookies"; | |
| export default function handler(_req: NextApiRequest, res: NextApiResponse) { | |
| // Calling our pure function using the `res` object, it will add the `set-cookie` header | |
| setCookie(res, "Next.js", "api-middleware!"); | |
| // Return the `set-cookie` header so we can display it in the browser and show that it works! | |
| res.end(JSON.stringify(res.getHeader("Set-Cookie"))); | |
| } | |