You asked an AI coding agent for an app and it works. The terminal prints http://localhost:8000, the page looks right, so you paste the link to a friend. They get "This site can't be reached."
Nothing is broken. localhost is not a place on the internet. It is a name for whichever computer is asking.
The short answer
-
localhost:8000means "port 8000 on this computer". On your laptop that is your dev server. On your friend's laptop it is their own machine, where nothing is listening. (If something is listening there, they will see their own app instead of yours.) - To share the app, it has to run somewhere other people can reach: on your machine behind a tunnel, or on a host.
- A public address is the easy half. The app also has to work there, and four things tend to fail on the first deploy: the database, the settings, the sign-in callback and the build. Each one is the same bug as
localhost:8000: something that was only true on your machine.
What localhost, 127.0.0.1 and :8000 mean
Your laptop Your friend's laptop +----------------------+ +----------------------+ | browser | | browser | | -> localhost:8000 | | -> localhost:8000 | | dev server on :8000 | | nothing on :8000 | +----------------------+ +----------------------+ page loads connection refused -
localhostis a hostname that resolves to your own machine.127.0.0.1is the same idea as an IPv4 address, and::1as an IPv6 one. Traffic to them is routed back inside the machine and never reaches the network. A server can listen on one and not the other, which is whylocalhostand127.0.0.1sometimes behave differently. -
:8000is a TCP port, one numbered door on that machine. Your dev server opened it, or its framework picked it. 8000 is the default for several Python tools (Django'srunserver,uvicornandpython -m http.server); Next.js defaults to 3000 and Vite to 5173. - The listening address matters too. A server bound to
127.0.0.1accepts connections only from the same machine. Bound to0.0.0.0it accepts them on every network interface, so a phone on the same Wi-Fi can try your laptop's local address (something like192.168.1.23:8000) if the firewall allows it. That address is private to your network, so it does nothing for a friend in another city.
Two things follow. The link only works while your dev server is running, so closing the terminal or letting the laptop sleep takes it down. And it only means something on your machine: anyone else needs a different address.
Three ways to get a link other people can open
One of the options below is ours (Tofu), and it is marked.
| Way | How it works | You still handle | Fits when |
|---|---|---|---|
| Tunnel (for example ngrok or Cloudflare Tunnel) | A small program on your machine opens a connection out to a relay. The relay gives you a public HTTPS address and forwards each request to localhost:8000 | Keeping your machine and dev server running; an address that often changes on each start unless you set up a fixed one | A quick look at a demo while you are at the keyboard |
| DIY hosting (a VPS, or a platform where you connect the repository and configure it yourself) | The app runs on a computer that stays on, at an address of its own | The build, start command, settings, HTTPS, database, updates and backups | A link for other people over days or weeks, and you want control of the setup |
| Tofu (ours) | Your coding agent sends the app to Tofu, which builds it and serves it at a public address | The app's own code, and a trigger from outside for anything that has to run on a timer | You want a link, and maybe a database and sign-in, without running a server yourself |
A tunnel is the quickest way to try it:
ngrok http 8000 cloudflared tunnel --url http://localhost:8000 Each prints a public HTTPS address that forwards to your dev server, once the tool is installed and set up (check the provider's docs). The catch is that the link dies with your machine, and anyone who has it can reach your dev server, including debug pages and admin routes. Stop the tunnel when you are done.
None of these does everything:
- A tunnel does not host anything. When your laptop sleeps, the link is gone.
- DIY hosting does not set itself up. HTTPS, updates and backups become your job.
- Tofu serves web apps that answer requests. It does not run background workers or schedules, it does not move records from a database on your computer (a new database starts empty, and the app's own setup files create the tables), and it does not fix the app's code.
Costs and limits differ between providers and change, so check each one's current pricing page. Whichever you choose, the next section applies.
The four things an AI-built app needs before you share it
A coding agent's first goal is usually to get the app running on your machine, so the defaults it picks can assume your machine: a database file in the project, a mock login, a base URL of http://localhost:3000, a key pasted into a local .env. All of that is fine on a laptop and wrong anywhere else.
1. A database the app can reach from where it runs
- What you see: pages that read data fail or come up empty on the public address, and the host's logs say something like
connect ECONNREFUSED 127.0.0.1:5432(5432 is the default Postgres port). - Why:
localhostin a connection string means "this computer", and on the host that is the host, not your laptop. A SQLite file inside the project has a different problem: on many managed hosts the project's files are replaced on every deploy, so the data resets. - Fix: create a database the host can reach, put its URL in a setting, and run your migrations against it. Your local records stay on your laptop unless you export them and import them there.
2. Settings that live on the host, not in the repo
- What you see: it works locally, but once deployed, calls to a payment, email or AI API fail with 401s, or a key comes back
undefined. - Why:
.envfiles are gitignored on purpose, so the host never saw yours. - Fix: list every variable the app reads, set each one in the host's environment settings, and keep the file out of the repository. If a key was ever committed, rotate it. In Next.js, variables prefixed
NEXT_PUBLIC_are inlined into the browser bundle at build time: set them before the build, and never put a secret in one. Any base-URL setting should hold the public address, notlocalhost.
3. A sign-in callback for the public address
- What you see: Google sign-in works at
localhost, but at the public address it fails withError 400: redirect_uri_mismatch, or you sign in and land back onlocalhost. - Why: OAuth providers only send people back to redirect URIs you registered, and the match is exact: scheme, host, port and path. Your client knows
http://localhost:8000/...and nothing else. Your app also builds the callback from a base-URL setting that probably still sayslocalhost. Google requires HTTPS for redirect URIs other than localhost, which is one more reason a public link needs it. - Fix: register the public callback URL in the provider's console (with Auth.js or NextAuth and Google the path is
/api/auth/callback/google), and set the app's base URL to the public address (NEXTAUTH_URLin NextAuth v4,AUTH_URLin Auth.js v5). If the consent screen is in Testing status, only the test users you list can sign in, so add your friend or they will hit an "Access blocked" page. With a tunnel whose address changes on every start, you would have to update the registered URI each time.
4. A build that starts from the source alone
- What you see: the host's build fails with "module not found", or it builds and a page, font or image is missing.
- Why: something exists only on your machine: a gitignored file, a package installed globally or in a virtual environment but missing from
package.jsonorrequirements.txt, a different Node or Python version, or an import whose capitalization differs from the filename (the default macOS filesystem ignores case, Linux build machines do not). - Fix: rehearse the build from the repository alone, as in the check below. If it fails there, it would have failed on the host. Also check the start command: on a host that runs your server as a process, the app should listen on
0.0.0.0and on the port the host provides (usually aPORTsetting), not a hard-coded127.0.0.1:8000.
A quick check before you share
# 1. Every place the code assumes this machine git grep -nE "localhost|127\.0\.0\.1" # 2. Every setting the code reads git grep -nE "process\.env|os\.environ|getenv" # 3. The host's build, rehearsed from committed files only (commit your work first) git clone . ../preflight && cd ../preflight npm ci && npm run build # or: pip install -r requirements.txt, then your build step Then confirm that the database exists on the host side with its tables created, that the sign-in provider knows the public callback URL and lets your testers in, and that every setting from step 2 is set on the host.
You can hand the first two steps to your agent:
Before I deploy: list every place this app assumes it runs on my computer (localhost URLs, local files, a local database, .env values, OAuth callbacks), every environment variable it reads, and the exact build and start commands. Don't change anything yet.
Which one to use
If someone only needs to look at a demo for ten minutes, a tunnel is enough. If the link has to live for days, use a host, and run the check above before you share it.
The longer version of this post, with each option's limits written out, is here: https://trytofu.ai/blog/why-cant-my-friend-open-localhost-8000
We make Tofu, one of the options above, so weigh that part accordingly. Corrections are welcome in the comments.
