Project: polish and deploy
Before launch an app needs polish: helpful not-found and error pages, per-page metadata, tests, a working production build and a deploy. This module polishes CourseHub, tests it with Vitest and Playwright, deploys it on Vercel + Neon and reads performance from the build output.
73.1 What is missing before launch
- Wrong course URL (e.g. /courses/vue-basics): plain Next.js 404 with no link back.
- Database down for a second: signup says "Email already registered" (completely wrong message).
- Every course tab title is just "CourseHub", so Google and share previews show no course details.
73.2 Custom 404: app/not-found.tsx
React (TSX)
import Link from "next/link"; export default function NotFound() { return ( <main className="mx-auto max-w-3xl p-6"> <h1 className="text-2xl font-bold">Page not found</h1> <p className="mt-2">This course or page does not exist.</p> <Link href="/" className="mt-4 underline"> Browse all courses </Link> </main> );}Output
# Page not foundThis course or page does not exist.Browse all courses- Special Next.js file: shown when no route matches or a page calls notFound().
- The Link back to / means the user never hits a dead end.
73.3 Error page with retry: app/error.tsx
React (TSX)
"use client"; type Props = { error: Error; retry: () => void };export default function ErrorPage(p: Props) { console.error(p.error); return ( <main className="mx-auto max-w-3xl p-6"> <h1 className="text-2xl font-bold">Something went wrong</h1> <p className="mt-2">Please try again in a moment.</p> <button onClick={() => p.retry()} className="mt-4"> Try again </button> </main> );}Output
# Something went wrongPlease try again in a moment.[button] Try again- Must be a client component ("use client"): an error boundary works in the browser.
- Shown when a page or server action throws an unexpected error; the error is logged.
- retry() fetches and renders that segment again from the server.
- No separate loading.tsx needed: the dashboard already has a Suspense fallback.
73.4 generateMetadata: a title for every course
React (TSX)
import type { Metadata } from "next"; export async function generateMetadata({ params,}: PageProps<"/courses/[slug]">): Promise<Metadata> { const { slug } = await params; const course = await getCourseBySlug(slug); if (!course) return { title: "Course not found" }; return { title: course.title, description: course.description, openGraph: { title: course.title }, };}Output
$ curl -s localhost:3000/courses/react-19<title>React 19 Complete | CourseHub</title><meta name="description" content="Components, hooks aur forms."/><meta property="og:title" content="React 19 Complete"/>- getCourseBySlug is "use cache", so the page does not run the DB query twice.
- A title template in the layout gives "React 19 Complete | CourseHub".
- openGraph.title appears in share previews.
73.5 Unit test with Vitest
TypeScript
import { describe, expect, test } from "vitest";import { formatPrice } from "./format"; describe("formatPrice", () => { test("adds ₹ and Indian commas", () => { expect(formatPrice(1499)).toBe("₹1,499"); expect(formatPrice(125000)).toBe("₹1,25,000"); }); test("free course shows ₹0", () => { expect(formatPrice(0)).toBe("₹0"); });});Output
$ npm test✓ lib/format.test.ts > formatPrice > adds ₹ and Indian commas✓ lib/format.test.ts > formatPrice > free course shows ₹0Test Files 1 passed (1)Tests 2 passed (2)- Unit tests for pure logic are the fastest and cheapest tests.
- If someone changes formatPrice's locale and breaks Indian lakh commas, this fails immediately.
73.6 End to end test with Playwright
TypeScript
import { test, expect } from "@playwright/test"; test("logged-in user can enroll", async ({ page }) => { await page.goto("/login"); await page.getByPlaceholder("Email").fill("priya@example.com"); await page.getByPlaceholder("Password").fill("secret1234"); await page.getByRole("button", { name: "Log in" }).click(); await expect(page).toHaveURL("/dashboard"); await page.goto("/courses/react-19"); await page.getByRole("button", { name: "Enroll" }).click(); await expect(page.getByText(/enrolled/i)).toBeVisible();});Output
$ npx playwright testRunning 1 test using 1 workerok 1 e2e\enroll.spec.ts:3:1 › logged-in user can enroll (1.5s)1 passed (4.1s)- Runs the whole flow in a real browser: log in, land on /dashboard, enroll.
- /enrolled/i matches both "Enrolled!" and "Already enrolled", so the test can be re-run.
| Point | Unit test (Vitest) | E2E test (Playwright) |
|---|---|---|
| Checks | One pure function (formatPrice) | A full user flow (login -> enroll) |
| Runs in | Node, no browser | A real browser against the running app |
| Speed / cost | Very fast, cheap | Slower, needs app + DB |
| How many | Many | A few, for the critical flows |
73.7 Deploy on Vercel + Neon
- Step 1
1.git push: code to a GitHub repo
- Step 2
2.Vercel import + env vars: DATABASE_URL (Neon), BETTER_AUTH_SECRET, BETTER_AUTH_URL
- Step 3
3.migrate deploy + db seed once on the production DB
- Step 4
4.Vercel builds: live URL coursehub.vercel.app
BETTER_AUTH_URL = the live URL
73.8 Checkpoint: will the Vercel build pass?
JSON
{ "scripts": { "dev": "next dev", "build": "next build", "start": "next start", "lint": "eslint" }}Output
$ npm run build> Build error occurredError: Turbopack build failed with 2 errors:Error: Module not found: Can't resolve '@/app/generated/prisma/client'- It fails: the generated Prisma client is in .gitignore and Prisma 7 does not generate it on install.
- A fresh clone has no client, so the import in lib/ cannot be resolved.
JSON
{ "scripts": { "dev": "next dev", "build": "prisma generate && next build", "start": "next start", "lint": "eslint", "test": "vitest run --reporter=verbose", "test:e2e": "playwright test" }}Output
$ npm run build> prisma generate && next build✔ Generated Prisma Client (7.10.1) to .\app\generated\prisma in 95ms✓ Compiled successfully in 15.3s○ / 1h 1d○ /courses/javascript-basics 1h 1d○ /courses/react-19 1h 1d○ /courses/nextjs-16-fullstack 1h 1d◐ /dashboardƒ /api/auth/[...all]- Fix: prisma generate && next build, so every fresh machine creates the client.
- The shadow database URL was made optional in the Prisma config (local only), otherwise the config would not load on Vercel.
73.9 Build output = performance report
| Symbol | Meaning | CourseHub routes |
|---|---|---|
| ○ Static | Static HTML from a CDN, revalidated (1h here) | / and the 3 course pages |
| ◐ Partial | Static shell arrives at once, user data streams in | /dashboard |
| ƒ Dynamic | Runs on the server for every request | /api/auth/[...all] |
- After deploy, check Core Web Vitals with Lighthouse or Vercel Speed Insights.
73.10 Common mistakes
TypeScript
import { APIError } from "better-auth/api";// ...try { await auth.api.signUpEmail({ body: r.data });} catch (e) { if (e instanceof APIError) return e.message; throw e;}- Wrong: catch { return "Email already registered"; } turns every error (even DB down) into that message and hides the real problem.
- Right (above): only a Better Auth APIError becomes a friendly message (e.g. User already exists); everything else is thrown to the error page and server logs.
- Misconception: run migrate dev on production. migrate dev creates new migrations, needs a shadow DB and may ask to reset on drift.
- In production always run migrate deploy: applies only committed migrations, never resets data.
73.11 Launch checklist
- not-found, error and metadata ready for every public page.
- Unit tests for pure logic + at least one e2e test of the main flow.
- Secrets only in Vercel env vars; never commit .env.
- prisma generate in the build script; only migrate deploy in production.
73.12 Interview tips
- "How would you take a Next.js app to production?": not-found + error boundaries + metadata first.
- Unit tests for pure logic plus a Playwright test for the critical flow.
- Deploy on Vercel with a hosted Postgres; secrets in env vars, migrations via migrate deploy.
- Check performance with the build output (○ ◐ ƒ) and Core Web Vitals.