SuperAPI AI Directory

cf-tunnel

Deployment & operations

View repository

Updated 10-16 08:36

About this skill

Cloudflare Tunnel management skill (unified version)

Goal: unify "temporary exposure + management panel + port management" into a single command entry point to avoid port chaos.

✅ Recommended entry point (unified Bun CLI)

bun ~/.pi/agent/skills/cf-tunnel/scripts/cf.ts

Command overview

# 启动临时暴露(等同 share start)
bun ~/.pi/agent/skills/cf-tunnel/scripts/cf.ts start --dir ./demos/html

# 暴露已有端口
bun ~/.pi/agent/skills/cf-tunnel/scripts/cf.ts start --port 8766
Expose a single file

bun ~/.pi/agent/skills/cf-tunnel/scripts/cf.ts start --file ./demos/html/index.html --route /index.html

Start/stop/view the panel

bun ~/.pi/agent/skills/cf-tunnel/scripts/cf.ts panel start --port 8788 --host 127.0.0.1 bun ~/.pi/agent/skills/cf-tunnel/scripts/cf.ts panel status bun ~/.pi/agent/skills/cf-tunnel/scripts/cf.ts panel stop

Overall status (share + panel)

bun ~/.pi/agent/skills/cf-tunnel/scripts/cf.ts status

Stop (stops all by default)

bun ~/.pi/agent/skills/cf-tunnel/scripts/cf.ts stop

Stop only share

bun ~/.pi/agent/skills/cf-tunnel/scripts/cf.ts stop --share

Stop only panel

bun ~/.pi/agent/skills/cf-tunnel/scripts/cf.ts stop --panel


---

## 功能特性

- 统一入口:`cf.ts` 同时管理 share / panel
- 端口自动避让:面板端口占用时自动切换到下一个可用端口
- 会话清晰:固定 tmux session 名
  - `cf-share-web`
  - `cf-share-tunnel`
  - `cf-share-panel`
- 状态聚合:一个命令看完整状态(本地服务 / tunnel / panel / 公网 URL)
- 向后兼容:`share.ts`、`panel.ts` 仍可直接使用

---

## 底层命令(兼容保留)

```bash
# share 底层
bun ~/.pi/agent/skills/cf-tunnel/scripts/share.ts start --dir ./demos/html
bun ~/.pi/agent/skills/cf-tunnel/scripts/share.ts status
bun ~/.pi/agent/skills/cf-tunnel/scripts/share.ts stop

# panel 底层
bun ~/.pi/agent/skills/cf-tunnel/scripts/panel.ts --port 8788 --host 127.0.0.1

It is recommended to prioritize using cf.ts; the underlying commands are mainly for debugging.


API and panel

Default address after starting the panel:

  • http://127.0.0.1:8788(if occupied, it will automatically avoid the port)

API:

  • GET /api/status current status
  • POST /api/start start (body supports port/dir/file/route)
  • POST /api/stop stop
  • GET /api/logs log tail
  • GET /api/history history
  • POST /api/history/clear clear history

Dependencies

# Cloudflared(如未安装)
wget -q https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
sudo dpkg -i cloudflared-linux-amd64.deb

Local static service priority:python3 > bunx > npx(fails directly when no tool is available)


Troubleshooting

  1. cf.ts status First check whether the three session types are online
  2. If the tunnel has no URL: check ~/.cf-tunnel/share-tunnel.log
  3. If the panel cannot be opened:cf.ts panel status check the actual port (it may have automatically avoided the port)
  4. Full reset:cf.ts stop --all then restart start