Skip to content

Share localhost / Next.js

Share a Next.js dev server at a public URL

next dev serves your app on localhost:3000, and whk share 3000 gives it an HTTPS link. Pages, Fast Refresh and Server Actions work with an untouched next.config, which is not what Next.js's own tunnel advice would lead you to expect.

# terminal 1: the dev server
npm run dev

# terminal 2: the link
whk share 3000

The link is https://<name>.sharehooks.cc and works until you press Ctrl-C. No whk yet? Install it and log in, which takes a minute.

Start free:
or sign up with email

Next.js at a glance

Dev server
npm run dev, port 3000
Share it
whk share 3000
Setting to add
None for whk share. allowedDevOrigins exists for tunnels that pass the public origin on to dev resources; the link sends those requests with your local origin.
Without it
Nothing through whk share. Other tunnels get 403 Unauthorized on /_next/* and the terminal warning Blocked cross-origin request to Next.js dev resource ... from "<host>".
Hot reload
Yes. Fast Refresh connects to /_next/hmr on the host the page was loaded from, and the socket comes through the link.
URLs and cookies
request.url reads https://localhost:3000/...; the public name is in the x-forwarded-host header. Redirect with paths, not with URLs built from request.url.

Your dev server gets each request with Host: localhost:3000; the public name travels in X-Forwarded-Host, with X-Forwarded-Proto: https. What your server sees has the rest.

Why allowedDevOrigins is not needed

Since 16.2, next dev blocks cross-origin requests to its dev-only assets and endpoints by default. It checks requests under /_next and /__nextjs, the Fast Refresh socket included, and compares the hostname of the Origin header with localhost and the entries of allowedDevOrigins. A request that fails gets 403 with the body Unauthorized, and the terminal prints Blocked cross-origin request to Next.js dev resource /_next/hmr from "<host>", followed by the config to add.

That is why the Next.js docs tell you to list a tunnel's hostname. whk share takes the other route: for WebSocket upgrades and for paths under /_next/ and /__nextjs, an Origin that is the preview's own address is sent to your dev server as http://localhost:3000. A visitor's page is same-origin with those resources, so Next.js sees what it would see from your own browser. Requests from any other site keep their Origin and are still refused.

If you use a tunnel that does not do this, or want the entry in place anyway, this is the setting. A * stands for exactly one label, which covers every preview name:

next.config.ts

import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  // Not needed for whk share; for tunnels that pass the public Origin on
  allowedDevOrigins: ["*.sharehooks.cc"],
};

export default nextConfig;

Entries are hostnames only, without https:// or a port, and the dev server must be restarted after the change.

Fast Refresh and Server Actions

The dev client builds its socket address from window.location, so a page opened at https://<name>.sharehooks.cc connects to wss://<name>.sharehooks.cc/_next/hmr (the path was /_next/webpack-hmr before 16.3). WebSockets pass through the link, and edits show up for whoever has the page open. Turbopack is the default bundler in Next.js 16 and needs nothing extra.

Server Actions carry their own CSRF check: Next.js compares the host of the Origin header with the app's host, taken from x-forwarded-host when present and from host otherwise. The link sets X-Forwarded-Host to the preview's name, the browser's Origin is the same name, and the action runs. experimental.serverActions.allowedOrigins is for proxies that do not forward the public host; without that header an action fails with status 500 and Invalid Server Actions request.

request.url says localhost

Inside a route handler, request.url and request.nextUrl.origin use the dev server's own hostname with the scheme from X-Forwarded-Proto: https://localhost:3000/.... The public name is only in the x-forwarded-host header. A redirect built the usual way, NextResponse.redirect(new URL("/login", request.url)), therefore answers with Location: https://localhost:3000/login, and the visitor's browser tries their own machine.

Redirects from proxy.ts (middleware), redirect() from next/navigation and any Location that is a path are sent as paths and work. In a route handler, redirect to a path, or build the origin from the forwarded headers, which is also right behind a production proxy:

app/api/go/route.ts

import { NextResponse, type NextRequest } from "next/server";

export function GET(request: NextRequest) {
  const host = request.headers.get("x-forwarded-host") ?? request.headers.get("host");
  const proto = request.headers.get("x-forwarded-proto") ?? "http";
  return NextResponse.redirect(new URL("/login", `${proto}://${host}`));
}

The same goes for absolute URLs you hand to someone else: an OAuth callback, a link in an email. In development metadataBase falls back to http://localhost:3000, so Open Graph image URLs point at localhost until you set it.

Images from next/image

The image optimizer answers /_next/image with Content-Disposition: attachment (the default of images.contentDispositionType). A share does not hand out downloads, with one exception made for exactly this: an image a page loads into an <img> is passed on. Pages render normally; opening an optimized image's URL on its own in a tab is refused.

Next.js questions

Sources

The Next.js settings and messages on this page are from the official documentation and source for Next.js 16.4, read on 12 November 2026. What the link does to a request is from the whk share docs.

Other frameworks

All 14 framework guides

Send someone your Next.js app

Sign up free, install the CLI and run whk share 3000.

or sign up with email

No credit card