A focused rewrite
// next.config.ts
async rewrites() {
return [{ source: '/api/:path*', destination: 'http://localhost:3001/:path*' }];
}The browser-facing path is forwarded; the API server still handles the request.
Topic
Definition
A Next.js rewrite or proxy forwards a matching web request to another destination while preserving a controlled browser-facing route shape.
In simpler words
It can change where a browser request goes, but it does not change who owns the API or who authorizes it.
Proxying can simplify a browser path, but it must preserve cookie, CORS, and error behavior intentionally.
A rewrite maps a request path to another destination. The browser may see one stable route while the upstream server receives the request, but domain validation and permission checks still happen upstream.
Proxying changes topology, not security. It can make development and same-origin browser requests easier, yet it can also hide cookie, header, and error-handling differences if configured casually.
// next.config.ts
async rewrites() {
return [{ source: '/api/:path*', destination: 'http://localhost:3001/:path*' }];
}The browser-facing path is forwarded; the API server still handles the request.
// Wrong assumption: “Only /api users can reach Nest now.”
// A rewrite does not block direct requests to the upstream API.
// Right: Nest validates the JWT and permissions for every request.Authorization belongs at the server that owns the protected resource.
Definition
A proxy must deliberately handle credentials, headers, origin rules, and non-success responses.
In simpler words
A convenient browser route is not a replacement for documenting the Nest API for other consumers.
Test cookie behavior in the deployed HTTPS topology, not only on localhost.
Avoid adding a proxy layer when direct, documented API access already meets the product need.
Live playground
Follow a browser request through a rewrite to the Nest API.
Rewrites change URL shape, not Nest authorization.
next-proxy
Test
At least 10 questions — mix of concept, syntax, practical, and logic. Score ≥ 80% (enforced by the API) to save progress.
Checking your session…
10 questions · concept 3 · syntax 2 · practical 3 · logic 2