To use PortPreview with a Next.js app, run next dev on port 3000, start npx portpreview 3000, and use the HTTPS URL for OAuth redirects, webhook route handlers, mobile previews, and sharing in-progress UI — no deploy required.
Why tunnel a Next.js app
Next.js is often the public face of a product: marketing pages, dashboards, and API route handlers in one repo. Third parties still cannot reach localhost. A tunnel gives you a stable public HTTPS origin while you iterate in next dev or next dev --turbo.
- Webhooks. Stripe, Clerk, and Resend POST to your
app/api/...routes. See Next.js webhook local testing for raw-body patterns. - OAuth. Register
https://your-tunnel.portpreview.dev/api/auth/callback/...in Auth0, Google, or GitHub during development. See test OAuth callbacks locally. - Mobile and stakeholder previews. Send the tunnel link to QA or design. See share a local dev server.
Quick start
- From your Next.js project:
npm run dev(default port 3000). - In a second terminal:
npx portpreview 3000. - Open the printed
https://....portpreview.devURL in a browser or phone. - Point external services at the same origin plus your API path.
App Router API routes behind a tunnel
Route handlers receive proxied requests with original headers intact — useful for webhook signatures. Keep webhook routes on the Node runtime when providers need Node crypto:
// app/api/health/route.ts
export async function GET() {
return Response.json({ ok: true });
}
For signature verification, read await request.text() before parsing JSON. Middleware that reads the body globally will break webhooks; exclude /api/webhooks in middleware.ts matcher.
Environment variables and public URLs
When client code must know its public origin (OAuth, absolute asset URLs), store the active tunnel in .env.local:
NEXT_PUBLIC_APP_URL=https://abc123.portpreview.dev
Restart next dev after changing env files. For server-only webhook secrets, use unprefixed vars like STRIPE_WEBHOOK_SECRET.
WebSockets and custom servers
If you run a custom Node server with socket.io alongside Next.js, PortPreview forwards WebSocket upgrades by default. Turbopack does not change tunnel behavior — only the bundler.
Security checklist
- Do not commit
.env.localor tunnel URLs to git. - Protect admin and preview routes with auth even on tunnels.
- Rotate tunnel sessions when sharing widely.
- Review localhost tunnel security.
Next.js documentation covers route handlers and env loading. Start PortPreview free for Next.js-friendly HTTPS tunnels.
