Skip to content

jimyag/portzero

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Portzero

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 的启发。

Features | 功能特性

  • 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.localhost out 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 PORT environment variable and --port/--host flags.

  • 零配置 HTTPS: 自动生成并信任本地根证书 (CA)。
  • 多项目支持: 采用主从架构,支持多个运行中的项目共享 80/443 端口。
  • Git 分支集成: 自动识别 Git 分支并将其作为子域名(如 feature.myapp.localhost)。
  • 泛域名支持: 原生支持 *.yourdomain.localhost
  • 局域网模式: 通过 mDNS 在局域网内暴露你的开发服务器(如 myapp.local)。
  • 循环检测: 内置代理循环检测保护。
  • 框架友好: 自动注入 PORT 环境变量及 --port/--host 参数。

Installation | 安装

go build -o portzero ./cmd/portzero

Usage | 使用方法

Basic Usage | 基础用法

Run 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 权限。

Options | 可选参数

  • --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

How it Works | 工作原理

  1. Leader Election: The first portzero instance acquires a file lock and becomes the Leader, binding to 80/443.

  2. Client Registration: Subsequent instances become Clients and register their random ports with the Leader via a Unix socket.

  3. Dynamic Proxying: The Leader inspects the Host header and routes traffic to the appropriate project port.

  4. Persistence: Routes are saved to routes.json, allowing the next Leader to recover state instantly if the current one stops.

  5. 主节点选举: 第一个启动的 portzero 实例会获取文件锁并成为 Leader,负责监听 80/443 端口。

  6. 从节点注册: 后续启动的实例作为 Client,通过 Unix Socket 将其分配的随机端口注册到 Leader。

  7. 动态代理: Leader 检查 Host 请求头并将流量转发到对应项目的端口。

  8. 状态持久化: 路由信息保存在 routes.json 中,确保 Leader 切换时能瞬间恢复状态。

License | 开源协议

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages