Skip to content

Commit efb09fd

Browse files
committed
Initial commit
0 parents  commit efb09fd

36 files changed

Lines changed: 11208 additions & 0 deletions

.github/workflows/ci.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
build:
14+
runs-on: macos-latest
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Install Rust stable
20+
uses: dtolnay/rust-toolchain@stable
21+
with:
22+
components: clippy
23+
24+
- name: Cache cargo registry and build
25+
uses: actions/cache@v4
26+
with:
27+
path: |
28+
~/.cargo/registry
29+
~/.cargo/git
30+
target
31+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
32+
restore-keys: |
33+
${{ runner.os }}-cargo-
34+
35+
- name: Build
36+
run: cargo build --release
37+
38+
- name: Test
39+
run: cargo test
40+
41+
- name: Clippy
42+
run: cargo clippy -- -D warnings

.github/workflows/release.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
env:
9+
CARGO_TERM_COLOR: always
10+
11+
jobs:
12+
build:
13+
strategy:
14+
matrix:
15+
include:
16+
- target: x86_64-apple-darwin
17+
os: macos-latest
18+
- target: aarch64-apple-darwin
19+
os: macos-latest
20+
- target: x86_64-unknown-linux-gnu
21+
os: ubuntu-latest
22+
- target: aarch64-unknown-linux-gnu
23+
os: ubuntu-latest
24+
25+
runs-on: ${{ matrix.os }}
26+
27+
steps:
28+
- uses: actions/checkout@v4
29+
30+
- name: Install Rust stable
31+
run: rustup toolchain install stable --target ${{ matrix.target }}
32+
33+
- name: Install cross-compilation tools (Linux ARM64)
34+
if: matrix.target == 'aarch64-unknown-linux-gnu'
35+
run: sudo apt-get update && sudo apt-get install -y gcc-aarch64-linux-gnu
36+
37+
- name: Cache cargo registry and build
38+
uses: actions/cache@v4
39+
with:
40+
path: |
41+
~/.cargo/registry
42+
~/.cargo/git
43+
target
44+
key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
45+
restore-keys: |
46+
${{ runner.os }}-${{ matrix.target }}-cargo-
47+
48+
- name: Build
49+
env:
50+
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: ${{ matrix.target == 'aarch64-unknown-linux-gnu' && 'aarch64-linux-gnu-gcc' || '' }}
51+
run: cargo build --release --target ${{ matrix.target }}
52+
53+
- name: Package
54+
run: |
55+
cd target/${{ matrix.target }}/release
56+
tar czf ../../../cfproxy-${{ matrix.target }}.tar.gz cfproxy
57+
cd ../../..
58+
59+
- name: Upload artifact
60+
uses: actions/upload-artifact@v4
61+
with:
62+
name: cfproxy-${{ matrix.target }}
63+
path: cfproxy-${{ matrix.target }}.tar.gz
64+
65+
release:
66+
needs: build
67+
runs-on: ubuntu-latest
68+
permissions:
69+
contents: write
70+
71+
steps:
72+
- uses: actions/checkout@v4
73+
74+
- name: Download all artifacts
75+
uses: actions/download-artifact@v4
76+
with:
77+
path: artifacts
78+
merge-multiple: true
79+
80+
- name: Create release
81+
env:
82+
GH_TOKEN: ${{ github.token }}
83+
run: |
84+
gh release create ${{ github.ref_name }} \
85+
--title "${{ github.ref_name }}" \
86+
--generate-notes \
87+
artifacts/*.tar.gz

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/target
2+
*.swp
3+
*.swo
4+
.DS_Store
5+
.env
6+
node_modules/
7+
package.json
8+
package-lock.json

CLAUDE.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
cfproxy is a Rust CLI that exposes localhost services to the internet via Cloudflare Tunnels with a rich ratatui-powered TUI dashboard. It automatically manages the `cloudflared` binary (download, cache, update) and provides real-time connection status, request metrics, and tunnel details.
8+
9+
## Build & Development Commands
10+
11+
```bash
12+
cargo build # Dev build
13+
cargo build --release # Release build
14+
cargo run -- 3000 # Run against local port 3000
15+
cargo test # Run all tests (unit + integration)
16+
cargo test <test_name> # Run a single test
17+
cargo clippy -- -D warnings # Lint (treat warnings as errors)
18+
cargo fmt # Format code
19+
cargo check # Type-check without building
20+
RUST_LOG=debug cargo run -- 3000 # Run with debug logging
21+
```
22+
23+
A `Makefile` wraps these: `make build`, `make test`, `make lint`, `make fmt`, `make run PORT=3000`.
24+
25+
## Dependencies
26+
27+
- **Rust toolchain** (1.70+) via rustup
28+
- **cloudflared** is auto-downloaded at runtime; no manual install needed
29+
30+
## Architecture
31+
32+
Async pipeline: CLI args → config → resolve/download `cloudflared` binary → spawn tunnel subprocess → parse stderr into typed `TunnelEvent`s via mpsc channel → drive TUI.
33+
34+
Key modules in `src/`:
35+
36+
- **main.rs** — Entry point, wires components together
37+
- **cli.rs** — CLI argument definitions (clap derive)
38+
- **config.rs** — Builds runtime `Config` from parsed args
39+
- **cloudflared.rs**`BinaryManager`: locate, cache, or download the cloudflared binary
40+
- **tunnel.rs** — Spawns cloudflared subprocess, parses stderr into `TunnelEvent`s
41+
- **event.rs**`TunnelEvent` enum (central data type shared across modules)
42+
- **metrics.rs** — Fetches/parses Prometheus metrics from cloudflared's local metrics server
43+
- **ui/** — TUI rendering and event loop (ratatui + crossterm), split into state, render, overlays, requests, detail, helpers
44+
- **proxy.rs** — Local reverse proxy (hyper) that captures HTTP requests for the TUI
45+
- **qr.rs** — QR code generation for tunnel URL
46+
- **har.rs** — HAR file export
47+
- **diff.rs** — Request diff utilities
48+
- **mock.rs** — Mock response rules (matched against incoming requests)
49+
- **settings.rs** — Persistent settings (`~/.config/cfproxy/settings.json`)
50+
- **cloudflare.rs** — Cloudflare API client (tunnels, DNS, ingress management)
51+
- **setup.rs** — Interactive setup wizard for custom domain configuration
52+
- **purge.rs** — Find and clean stale/orphaned tunnels and DNS records
53+
- **doctor.rs** — Diagnostic checks (settings, binary, network, API, tunnel, DNS)
54+
- **error.rs** — Unified error type and `Result` alias
55+
56+
Integration tests live in `tests/integration.rs`.

0 commit comments

Comments
 (0)