[{"id":"nextbebeg-001","courseId":"nextjs-backend-beginner","domain":"server-backend","topic":"Route Handler file convention","prompt":"A teammate adds app/dashboard/route.ts with a GET handler, but app/dashboard/page.tsx already exists. Next.js reports a conflict. Why?","hint":"Think about which file answers the request for a single URL.","source":"https://nextjs.org/docs/app/getting-started/route-handlers#route-resolution","interaction":{"type":"single"},"options":[{"id":"a","text":"Route Handlers must live under an app/api folder to be recognised.","whyNot":"Route Handlers can be nested anywhere inside app; the api folder is only a convention."},{"id":"b","text":"A route.ts and a page.tsx cannot sit at the same route segment, because each takes over all HTTP verbs for that route.","why":"The docs say there cannot be a route file at the same route as a page file. Move the handler to another segment, such as app/api/dashboard/route.ts."},{"id":"c","text":"Route Handlers only support POST, so exporting GET is rejected.","whyNot":"GET, POST, PUT, PATCH, DELETE, HEAD and OPTIONS are all supported."},{"id":"d","text":"page.tsx must be renamed to page.server.tsx before a handler can share its folder.","whyNot":"There is no such convention; the two files simply cannot share one segment."}],"answer":"b","explanation":"route.ts is the lowest-level routing primitive: it answers every HTTP verb for its segment, so it cannot share a segment with page.tsx.","concept":"route.ts is the lowest-level routing primitive: it answers every HTTP verb for its segment, so it cannot share a segment with page.tsx.","rev":1,"kind":"scenario","takeaways":["One segment, one owner: either a page or a route handler, never both."]},{"id":"nextbebeg-002","courseId":"nextjs-backend-beginner","domain":"server-backend","topic":"Server Action authorization","prompt":"The /admin page redirects anyone who isn't an admin. A form on it calls this Server Action, which has no check of its own. An interviewer asks whether this is safe. What's the best answer?","hint":"Ask how else, besides the page's form, this function can be reached.","source":"https://nextjs.org/docs/app/guides/data-security#authentication-and-authorization","interaction":{"type":"single"},"options":[{"id":"a","text":"Yes: the page-level redirect also protects every action defined on that page.","whyNot":"The docs say a page-level check does not extend to the Server Actions in it; the action is a separate entry point."},{"id":"b","text":"Yes: action IDs are encrypted, so nobody outside the UI can ever call it.","whyNot":"Encrypted IDs reduce risk, but the docs still say to treat actions as reachable by direct POST requests."},{"id":"c","text":"It's only safe if the form uses method=\"post\" instead of the default.","whyNot":"Actions are always invoked with POST; the form method doesn't add any access control."},{"id":"d","text":"No: a Server Action can be called with a direct POST request, so it must check authentication and authorization itself.","why":"Server Functions are reachable outside your UI. Verify the session and the user's permission inside every action."}],"answer":"d","explanation":"Each Server Action is a public POST endpoint, so authentication and authorization must be checked inside the action, not only on the page.","concept":"Each Server Action is a public POST endpoint, so authentication and authorization must be checked inside the action, not only on the page.","rev":1,"kind":"scenario","code":"'use server'\n\nexport async function deleteUser(\n  id: string\n) {\n  await db.user.delete({ where: { id } })\n}","takeaways":["Treat every Server Action like a public API route: check who is calling and what they may do."]},{"id":"nextbebeg-003","courseId":"nextjs-backend-beginner","domain":"server-backend","topic":"proxy.ts basics","prompt":"A team upgrading to Next.js 16 sees middleware.ts flagged as deprecated. Which TWO statements about proxy.ts are true?","hint":"One is about the file's naming history, the other about where its code runs.","source":"https://nextjs.org/docs/app/api-reference/file-conventions/proxy","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"It replaces the deprecated middleware.ts convention, and a codemod renames both the file and the function.","why":"Next.js 16 renamed middleware to proxy; npx @next/codemod middleware-to-proxy does the rename."},{"id":"b","text":"It runs after the page renders, so it can read and edit the rendered HTML.","whyNot":"Proxy runs before routes are rendered, to rewrite, redirect, change headers or respond directly."},{"id":"c","text":"It defaults to the Node.js runtime, and setting the runtime config option in it throws an error.","why":"The docs state Proxy defaults to Node.js and the runtime option isn't available in Proxy files."},{"id":"d","text":"Without a matcher it runs only on page routes, never on static files or images.","whyNot":"Without a matcher it runs on every request, including _next/static, _next/image and public assets."}],"answer":"ac","explanation":"proxy.ts is the Next.js 16 name for middleware: it runs before routes render, on Node.js by default, and should be scoped with a matcher.","concept":"proxy.ts is the Next.js 16 name for middleware: it runs before routes render, on Node.js by default, and should be scoped with a matcher.","rev":1,"kind":"scenario","takeaways":["proxy.ts = old middleware.ts, Node.js by default, runs before rendering; scope it with a matcher."]},{"id":"nextbebeg-004","courseId":"nextjs-backend-beginner","domain":"server-backend","topic":"Streaming with loading.js","prompt":"A product page waits two seconds on a slow query, and users stare at a blank screen. A junior adds app/products/loading.tsx with a skeleton. What does this file do?","hint":"Which React feature shows a fallback while something below it is still waiting?","source":"https://nextjs.org/docs/app/api-reference/file-conventions/loading","interaction":{"type":"single"},"options":[{"id":"a","text":"It wraps the page in a Suspense boundary, so the skeleton shows at once and the page content streams in when ready.","why":"loading.js wraps page.js in a Suspense boundary and shows an instant loading state while the segment's content streams in."},{"id":"b","text":"It caches the slow query, so only the first visitor waits.","whyNot":"loading.js only provides fallback UI; it doesn't cache any data."},{"id":"c","text":"It moves the query to the browser so the server can answer faster.","whyNot":"The page still renders on the server; only the fallback is shown earlier."},{"id":"d","text":"It holds the response until the query finishes, then fades the page in.","whyNot":"That is the blank-screen behaviour it removes; the fallback is sent before the data is ready."}],"answer":"a","explanation":"loading.js gives a route segment an instant fallback inside a Suspense boundary, so the server streams the real content in when it is ready.","concept":"loading.js gives a route segment an instant fallback inside a Suspense boundary, so the server streams the real content in when it is ready.","rev":1,"kind":"scenario","takeaways":["loading.tsx = an automatic Suspense boundary: instant fallback, then streamed content."]},{"id":"nextbebeg-005","courseId":"nextjs-backend-beginner","domain":"server-backend","topic":"NEXT_PUBLIC_ variables at build time","prompt":"A team builds one Docker image and promotes it from staging to production. Client code reads process.env.NEXT_PUBLIC_API_URL, and production still calls the staging API. Why?","hint":"When does Next.js decide the value of a variable that reaches the browser?","source":"https://nextjs.org/docs/app/guides/environment-variables#bundling-environment-variables-for-the-browser","interaction":{"type":"single"},"options":[{"id":"a","text":"Next.js reads NEXT_PUBLIC_ values only from .env.local, which containers ignore.","whyNot":"NEXT_PUBLIC_ values can come from process.env or any .env file; the source isn't the problem."},{"id":"b","text":"Containers must be restarted twice before new variables are read.","whyNot":"Restarts don't matter: the value is already written into the built JavaScript."},{"id":"c","text":"NEXT_PUBLIC_ values are inlined into the JavaScript bundle during next build, so they keep the value from when the image was built.","why":"The docs say public variables are frozen at build time. Read server-only variables at request time, or build per environment."},{"id":"d","text":"Browsers cache environment variables until users clear their storage.","whyNot":"Browsers never see environment variables, only the values inlined into the bundle."}],"answer":"c","explanation":"Only NEXT_PUBLIC_ variables reach the browser, and they are inlined at build time; plain variables stay on the server and can be read at runtime.","concept":"Only NEXT_PUBLIC_ variables reach the browser, and they are inlined at build time; plain variables stay on the server and can be read at runtime.","rev":1,"kind":"scenario","takeaways":["NEXT_PUBLIC_ means public and baked in at build time; never put a secret in one."]}]