/pages/api/hello.js. After deploying to Vercel, what will be the behavior when you visit /api/hello in the browser?export default function handler(req, res) { res.status(200).json({ message: 'Hello from API!' }); }
Vercel natively supports Next.js API routes. When deployed, visiting /api/hello returns the JSON response defined in the handler.
API_KEY in your Next.js app deployed on Vercel. Which syntax correctly accesses this variable in your code?Server-side environment variables are accessed via process.env.VARIABLE_NAME. The NEXT_PUBLIC_ prefix is for variables exposed to the browser.
/pages/posts/[id].js. Visiting /posts/123 on Vercel returns a 500 error, but it works locally. What is the most likely cause?Dynamic routes require getStaticPaths for static generation or getServerSideProps for server-side rendering. Missing these causes build or runtime errors on Vercel.
import { useState, useEffect } from 'react'; export default function Counter() { const [count, setCount] = useState(0); useEffect(() => { const timer = setInterval(() => { setCount(c => c + 1); }, 1000); return () => clearInterval(timer); }, []); return <p>Count: {count}</p>; }
The component uses useEffect to start a timer that increments the count every second. This runs on the client side after hydration, so the count updates as expected.
Vercel deploys each Next.js API route as a separate serverless function. These functions start on demand when a request comes in, scaling automatically.