Back to News
Advertisement
ooctopoc about 4 hours ago 5 commentsRead Article on portzero.net

ES version is available. Content is displayed in original English for accuracy.

Hi HN,

Recently I wasted several hours wrangling my dev environment only to find out that the browser frontend was talking to the wrong version of the backend. This got me thinking--why on earth are we still using simple numbers to describe which process to connect to? Why not use names instead? I thought of all the times a program wouldn't start because of port conflicts. The more I thought about it, the crazier it seemed.

Modern operating systems already offer no-conflict ports: if you make your TCP server listen on port 0, the OS assigns you a random available port. But that only solves half the problem.

I built the other half: PortZero. It's a GPLv3 program that watches for processes (and docker containers!) with a special PZ_TUNNEL environment variable:

  PZ_TUNNEL=myapp-{branch}.portzero.local:80 npm run dev
When it sees such a process or container, PortZero does this:

1. Create a virtual NIC (if it hasn't already)

2. Create a new virtual IP address

3. Create a DNS record that substitutes things like {branch} based on the working directory of the process, and points at that virtual IP address

4. Start listening on that virtual IP address on the port of your choice (e.g. port 80 for http, port 443 for https, port 5432 for postgresql)

5. Forward any TCP connections to that virtual IP address / virtual port to the random, OS-assigned port that your process or container is actually listening on

The result is you don't have to think about ports anymore, you just have to think about subdomains. You can have multiple services available on port 80 without conflicts, as long as they have different portzero.local subdomains.

It does some other cool stuff like:

- Enable HTTPS on local HTTP services by creating a local CA and registering it on your machine

- Enable cloud tunnels so you can access your apps on other devices (paid feature)

Links:

https://portzero.net/docs/

https://github.com/PortZeroNetwork/portzero

Advertisement

⚡ Community Insights

Discussion Sentiment

50% Positive

Analyzed from 230 words in the discussion.

Trending Topics

#srv#code#support#need#backend#something#dev#environment#browser#why

Discussion (5 Comments)Read Original on HackerNews

snowe201014 minutes ago
Wild to vibe code something in a week then charge $50/month for it. I understand servers cost money but lol there’s no way the costs are that high. Also insane the amount of code generated here.
wannabe44about 1 hour ago
> Recently I wasted several hours wrangling my dev environment only to find out that the browser frontend was talking to the wrong version of the backend.

I have never faced this problem even though I hard-code the port. It's because I run the server program through VS Code's debugger. If there's already a session, it would warn me.

ignoramousabout 3 hours ago
> why on earth are we still using simple numbers to describe which process to connect to? Why not use names instead.

Not super popular, but: https://en.wikipedia.org/wiki/SRV_record

yjftsjthsd-habout 2 hours ago
Yep, my immediate reaction was "because browsers refuse to support SRV records" (although I think there was some new variant that kinda worked?)
octopocabout 2 hours ago
True! But, you wouldn't just need SRV support in browsers--you'd need it in every part of your dev environment / stack that touches the network. If your backend talks to a database, then your backend needs to support SRV. So you need SRV support in your standard library and your browser.

But at a larger level this tool just makes everything work so smoothly. If you have two services with the same name, it pops up a notification in the tray. If you start a new process with a different name, you don't have to configure SRV; the DNS just becomes available automatically. HTTPS is auto configured. That sort of thing.

I think somebody could one day make something like this that was based on SRV, but it would still need all those niceties to make it work well for developers.