Next.js Expert

Preview — 3 of 10 questions

How do you let a Next.js app import TypeScript-source packages from the workspace?

javascript
codejump/
├── apps/web/          Next.js app
├── packages/ui/       shared components (ships .ts/.tsx source)
└── packages/types/    shared types
ACopy the shared code into the app
BNext.js cannot import code from outside its own directory
CAdd the packages to transpilePackages in next.config.ts so Next.js compiles their source, depend on them with the workspace protocol ("@codejump/ui": "workspace:*"), and list them in pnpm-workspace.yaml
DDynamically import() every workspace package

How do you implement homepage A/B testing at the middleware level?

javascript
// middleware.ts
export function middleware(request: NextRequest) { /* assign + route a variant */ }
AIn middleware, read a variant cookie; if absent, assign one (e.g. 50/50) and set it on the response; then NextResponse.rewrite() to the chosen variant's internal path so the URL stays / but the content differs. Analytics reads the same cookie
BUse useEffect on the client to randomly show variant A or B
CServe each variant from a separate domain
DA/B testing is impossible without a third-party service

How do you get the visitor's country in middleware on Next.js 15?

AImport geoip-lite and call it with request.ip
BCall the Google Maps API on every request
CGeolocation is not possible in Next.js
DOn Vercel, request.geo / request.ip were removed in Next.js 15 — use geolocation(request) and ipAddress(request) from @vercel/functions. Self-hosted, parse x-forwarded-for and look it up against a geo-IP database (Edge-compatible)

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.