portzero is a zero-config local development proxy that replaces port numbers with stable, named URLs (e.g., https://myapp.localhost). It provides automatic HTTPS, multi-project support, and Git branch integration, heavily inspired by Vercel's Portless.
portzero 是一个零配置的本地开发代理工具,旨在用稳定的、具名的域名(如 https://myapp.localhost)取代传统的端口号。它提供自动 HTTPS、多项目共存支持以及 Git 分支集成,深受 Vercel Portless 的启发。
- Zero-config HTTPS: Automatically generates and trusts a local CA.
- Multi-project Support: Shared 80/443 ports across multiple running projects via a leader/client architecture.
- Git Branch Integration: Automatically uses your current Git branch as a subdomain (e.g.,
feature.myapp.localhost). - Wildcard Subdomains: Supports
*.yourdomain.localhostout of the box. - LAN Mode: Expose your dev server to the local network via mDNS (
myapp.local). - Loop Detection: Built-in protection against proxy loops.
- Framework Friendly: Automatically injects
PORTenvironment variable and--port/--hostflags.
- 零配置 HTTPS: 自动生成并信任本地根证书 (CA)。
- 多项目支持: 采用主从架构,支持多个运行中的项目共享 80/443 端口。
- Git 分支集成: 自动识别 Git 分支并将其作为子域名(如
feature.myapp.localhost)。 - 泛域名支持: 原生支持
*.yourdomain.localhost。 - 局域网模式: 通过 mDNS 在局域网内暴露你的开发服务器(如
myapp.local)。 - 循环检测: 内置代理循环检测保护。
- 框架友好: 自动注入
PORT环境变量及--port/--host参数。
go build -o portzero ./cmd/portzeroRun your development command through portzero:
使用 portzero 运行你的开发命令:
sudo ./portzero npm run dev
# Note: sudo is required to bind to ports 80 and 443.
# 注意:绑定 80 和 443 端口通常需要 sudo 权限。--domain: Set the base domain (default:myapp.localhost).--lan: Enable LAN mode to access from other devices (uses mDNS).--worktree: Enable/disable branch-based subdomains (default: true).--listen-addr: Specify the address to listen on (default:127.0.0.1).
# Example: Custom domain and LAN mode
# 示例:自定义域名并开启局域网模式
sudo ./portzero --domain project.test --lan npm run dev-
Leader Election: The first
portzeroinstance acquires a file lock and becomes the Leader, binding to 80/443. -
Client Registration: Subsequent instances become Clients and register their random ports with the Leader via a Unix socket.
-
Dynamic Proxying: The Leader inspects the
Hostheader and routes traffic to the appropriate project port. -
Persistence: Routes are saved to
routes.json, allowing the next Leader to recover state instantly if the current one stops. -
主节点选举: 第一个启动的
portzero实例会获取文件锁并成为 Leader,负责监听 80/443 端口。 -
从节点注册: 后续启动的实例作为 Client,通过 Unix Socket 将其分配的随机端口注册到 Leader。
-
动态代理: Leader 检查
Host请求头并将流量转发到对应项目的端口。 -
状态持久化: 路由信息保存在
routes.json中,确保 Leader 切换时能瞬间恢复状态。
MIT