Use a custom local domain instead of localhost:3000

http://localhost:3000 works. It also breaks a few real-world checks early:

cookies scoped to a real-looking host
absolute URLs in emails and webhooks
multi-app setups (app, api, admin)
OAuth redirect allowlists that hate bare localhost quirks

A loc…


This content originally appeared on DEV Community and was authored by Locahl

http://localhost:3000 works. It also breaks a few real-world checks early:

  • cookies scoped to a real-looking host
  • absolute URLs in emails and webhooks
  • multi-app setups (app, api, admin)
  • OAuth redirect allowlists that hate bare localhost quirks

A local hostname like myapp.test is often cleaner.

1. Add the hostname

In /etc/hosts (macOS/Linux) or C:\Windows\System32\drivers\etc\hosts (Windows):

127.0.0.1   myapp.test
127.0.0.1   api.myapp.test

Prefer .test. It is reserved for testing. Avoid inventing fake .com names you might later need for real DNS.

Flush DNS after saving.

2. Point your app at it

Many stacks already bind 0.0.0.0 or 127.0.0.1. You only change the URL you open:

http://myapp.test:3000

If the framework reads HOST / APP_URL:

APP_URL=http://myapp.test:3000

Keep the port unless you put a reverse proxy in front.

3. Optional: drop the port with a proxy

Caddy example:

myapp.test {
  reverse_proxy localhost:3000
}

Then open http://myapp.test. Same idea with nginx or Traefik.

4. HTTPS locally

Some features need secure cookies or HTTPS redirects.

Options:

  • Caddy or mkcert for a local cert on myapp.test
  • Your framework's built-in HTTPS in development

Do not fight browser warnings with a public domain pointed at 127.0.0.1 unless you control that name.

5. Frontend and API on sibling hosts

127.0.0.1   app.myapp.test
127.0.0.1   api.myapp.test

Frontend on :3000, API on :4000. CORS and cookie domains become closer to production:

Domain=.myapp.test

That is often the whole reason to stop using plain localhost.

Checklist when it "does not work"

  1. Hosts line exists and is not commented
  2. DNS cache flushed
  3. App is listening on the port you typed
  4. You opened myapp.test, not localhost
  5. Proxy config matches the hostname if you use one

Terminal check:

ping -c 1 myapp.test
# should show 127.0.0.1

When to skip this

Throwaway demos and single-file experiments are fine on localhost.

Reach for a custom local domain when cookies, redirects, or multiple services start fighting you. One hosts line usually ends the fight.

If you switch hosts a lot, a small desktop manager helps keep profiles and DNS flush in one place: Locahl.


This content originally appeared on DEV Community and was authored by Locahl


Print Share Comment Cite Upload Translate Updates
APA

Locahl | Sciencx (2026-07-16T22:28:29+00:00) Use a custom local domain instead of localhost:3000. Retrieved from https://www.scien.cx/2026/07/16/use-a-custom-local-domain-instead-of-localhost3000/

MLA
" » Use a custom local domain instead of localhost:3000." Locahl | Sciencx - Thursday July 16, 2026, https://www.scien.cx/2026/07/16/use-a-custom-local-domain-instead-of-localhost3000/
HARVARD
Locahl | Sciencx Thursday July 16, 2026 » Use a custom local domain instead of localhost:3000., viewed ,<https://www.scien.cx/2026/07/16/use-a-custom-local-domain-instead-of-localhost3000/>
VANCOUVER
Locahl | Sciencx - » Use a custom local domain instead of localhost:3000. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2026/07/16/use-a-custom-local-domain-instead-of-localhost3000/
CHICAGO
" » Use a custom local domain instead of localhost:3000." Locahl | Sciencx - Accessed . https://www.scien.cx/2026/07/16/use-a-custom-local-domain-instead-of-localhost3000/
IEEE
" » Use a custom local domain instead of localhost:3000." Locahl | Sciencx [Online]. Available: https://www.scien.cx/2026/07/16/use-a-custom-local-domain-instead-of-localhost3000/. [Accessed: ]
rf:citation
» Use a custom local domain instead of localhost:3000 | Locahl | Sciencx | https://www.scien.cx/2026/07/16/use-a-custom-local-domain-instead-of-localhost3000/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.