fbi-proxy 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +31 -0
- package/.github/workflows/release.yml +112 -0
- package/.releaserc.json +37 -0
- package/CHANGELOG.md +17 -0
- package/Caddyfile +19 -0
- package/Dockerfile +38 -0
- package/INSTALL.md +161 -0
- package/LICENSE +21 -0
- package/PINGORA_PROXY.md +127 -0
- package/README.md +158 -0
- package/RUST_PROXY.md +85 -0
- package/build-proxy.bat +15 -0
- package/build-proxy.sh +15 -0
- package/bun.lock +1238 -0
- package/docker-compose.yml +9 -0
- package/package.json +36 -0
- package/release/proxy-linux-arm64/proxy-linux-arm64 +0 -0
- package/release/proxy-linux-x64/proxy-linux-x64 +0 -0
- package/release/proxy-macos-arm64/proxy-macos-arm64 +0 -0
- package/release/proxy-macos-x64/proxy-macos-x64 +0 -0
- package/release/proxy-windows-arm64.exe/proxy-windows-arm64.exe +0 -0
- package/release/proxy-windows-x64.exe/proxy-windows-x64.exe +0 -0
- package/release-flat/proxy-linux-arm64 +0 -0
- package/release-flat/proxy-linux-x64 +0 -0
- package/release-flat/proxy-macos-arm64 +0 -0
- package/release-flat/proxy-macos-x64 +0 -0
- package/release-flat/proxy-windows-arm64.exe +0 -0
- package/release-flat/proxy-windows-x64.exe +0 -0
- package/rs/.cargo/config.toml +5 -0
- package/rs/Cargo.lock +1220 -0
- package/rs/Cargo.toml +19 -0
- package/rs/build-windows.bat +60 -0
- package/rs/proxy.rs +248 -0
- package/ts/cli.ts +148 -0
- package/tsconfig.json +22 -0
package/.gitattributes
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Auto detect text files and perform LF normalization
|
|
2
|
+
* text=auto
|
|
3
|
+
|
|
4
|
+
# Explicitly declare text files you want to always be normalized and converted
|
|
5
|
+
# to native line endings on checkout.
|
|
6
|
+
*.ts text
|
|
7
|
+
*.js text
|
|
8
|
+
*.json text
|
|
9
|
+
*.yml text
|
|
10
|
+
*.yaml text
|
|
11
|
+
*.md text
|
|
12
|
+
*.txt text
|
|
13
|
+
*.sh text eol=lf
|
|
14
|
+
*.bat text eol=crlf
|
|
15
|
+
|
|
16
|
+
# Declare files that will always have CRLF line endings on checkout.
|
|
17
|
+
*.bat text eol=crlf
|
|
18
|
+
|
|
19
|
+
# Declare files that will always have LF line endings on checkout.
|
|
20
|
+
*.sh text eol=lf
|
|
21
|
+
|
|
22
|
+
# Denote all files that are truly binary and should not be modified.
|
|
23
|
+
*.png binary
|
|
24
|
+
*.jpg binary
|
|
25
|
+
*.jpeg binary
|
|
26
|
+
*.gif binary
|
|
27
|
+
*.ico binary
|
|
28
|
+
*.exe binary
|
|
29
|
+
*.dll binary
|
|
30
|
+
*.so binary
|
|
31
|
+
*.dylib binary
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
name: Build and Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- main
|
|
10
|
+
workflow_dispatch:
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build:
|
|
14
|
+
name: Build proxy binary
|
|
15
|
+
runs-on: ${{ matrix.os }}
|
|
16
|
+
strategy:
|
|
17
|
+
matrix:
|
|
18
|
+
include:
|
|
19
|
+
- os: ubuntu-latest
|
|
20
|
+
target: x86_64-unknown-linux-gnu
|
|
21
|
+
binary_name: proxy-linux-x64
|
|
22
|
+
- os: ubuntu-latest
|
|
23
|
+
target: aarch64-unknown-linux-gnu
|
|
24
|
+
binary_name: proxy-linux-arm64
|
|
25
|
+
- os: windows-latest
|
|
26
|
+
target: x86_64-pc-windows-msvc
|
|
27
|
+
binary_name: proxy-windows-x64.exe
|
|
28
|
+
- os: windows-latest
|
|
29
|
+
target: aarch64-pc-windows-msvc
|
|
30
|
+
binary_name: proxy-windows-arm64.exe
|
|
31
|
+
- os: macos-latest
|
|
32
|
+
target: x86_64-apple-darwin
|
|
33
|
+
binary_name: proxy-macos-x64
|
|
34
|
+
- os: macos-latest
|
|
35
|
+
target: aarch64-apple-darwin
|
|
36
|
+
binary_name: proxy-macos-arm64
|
|
37
|
+
|
|
38
|
+
steps:
|
|
39
|
+
- uses: actions/checkout@v4
|
|
40
|
+
|
|
41
|
+
- name: Install Rust
|
|
42
|
+
uses: dtolnay/rust-toolchain@stable
|
|
43
|
+
with:
|
|
44
|
+
targets: ${{ matrix.target }}
|
|
45
|
+
|
|
46
|
+
- name: Install cross-compilation tools
|
|
47
|
+
if: matrix.target == 'aarch64-unknown-linux-gnu'
|
|
48
|
+
run: |
|
|
49
|
+
sudo apt-get update
|
|
50
|
+
sudo apt-get install -y gcc-aarch64-linux-gnu
|
|
51
|
+
|
|
52
|
+
- name: Build binary
|
|
53
|
+
working-directory: rs
|
|
54
|
+
run: |
|
|
55
|
+
cargo build --release --target ${{ matrix.target }}
|
|
56
|
+
|
|
57
|
+
- name: Prepare binary
|
|
58
|
+
shell: bash
|
|
59
|
+
run: |
|
|
60
|
+
mkdir -p release
|
|
61
|
+
if [ "${{ matrix.os }}" = "windows-latest" ]; then
|
|
62
|
+
cp rs/target/${{ matrix.target }}/release/proxy.exe release/${{ matrix.binary_name }}
|
|
63
|
+
else
|
|
64
|
+
cp rs/target/${{ matrix.target }}/release/proxy release/${{ matrix.binary_name }}
|
|
65
|
+
chmod +x release/${{ matrix.binary_name }}
|
|
66
|
+
fi
|
|
67
|
+
|
|
68
|
+
- name: Upload binary artifact
|
|
69
|
+
uses: actions/upload-artifact@v4
|
|
70
|
+
with:
|
|
71
|
+
name: ${{ matrix.binary_name }}
|
|
72
|
+
path: release/${{ matrix.binary_name }}
|
|
73
|
+
|
|
74
|
+
release:
|
|
75
|
+
name: Semantic Release
|
|
76
|
+
needs: build
|
|
77
|
+
runs-on: ubuntu-latest
|
|
78
|
+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
|
|
79
|
+
permissions:
|
|
80
|
+
contents: write
|
|
81
|
+
id-token: write
|
|
82
|
+
packages: write
|
|
83
|
+
steps:
|
|
84
|
+
- uses: actions/checkout@v4
|
|
85
|
+
with:
|
|
86
|
+
fetch-depth: 0
|
|
87
|
+
token: ${{ secrets.GITHUB_TOKEN }}
|
|
88
|
+
|
|
89
|
+
- name: Setup Bun
|
|
90
|
+
uses: oven-sh/setup-bun@v2
|
|
91
|
+
with:
|
|
92
|
+
bun-version: latest
|
|
93
|
+
|
|
94
|
+
- name: Install dependencies
|
|
95
|
+
run: bun install --frozen-lockfile
|
|
96
|
+
|
|
97
|
+
- name: Download all artifacts
|
|
98
|
+
uses: actions/download-artifact@v4
|
|
99
|
+
with:
|
|
100
|
+
path: release
|
|
101
|
+
|
|
102
|
+
- name: Flatten artifacts
|
|
103
|
+
run: |
|
|
104
|
+
mkdir -p release-flat
|
|
105
|
+
find release -type f -exec cp {} release-flat/ \;
|
|
106
|
+
ls -la release-flat/
|
|
107
|
+
|
|
108
|
+
- name: Run semantic-release
|
|
109
|
+
env:
|
|
110
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
111
|
+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
112
|
+
run: bunx semantic-release
|
package/.releaserc.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"branches": ["main"],
|
|
3
|
+
"plugins": [
|
|
4
|
+
"@semantic-release/commit-analyzer",
|
|
5
|
+
"@semantic-release/release-notes-generator",
|
|
6
|
+
[
|
|
7
|
+
"@semantic-release/changelog",
|
|
8
|
+
{
|
|
9
|
+
"changelogFile": "CHANGELOG.md"
|
|
10
|
+
}
|
|
11
|
+
],
|
|
12
|
+
[
|
|
13
|
+
"@semantic-release/npm",
|
|
14
|
+
{
|
|
15
|
+
"npmPublish": true
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
[
|
|
19
|
+
"@semantic-release/github",
|
|
20
|
+
{
|
|
21
|
+
"assets": [
|
|
22
|
+
{
|
|
23
|
+
"path": "release/**",
|
|
24
|
+
"label": "Binary releases"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
[
|
|
30
|
+
"@semantic-release/git",
|
|
31
|
+
{
|
|
32
|
+
"assets": ["package.json", "CHANGELOG.md"],
|
|
33
|
+
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
]
|
|
37
|
+
}
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# 1.0.0 (2025-07-25)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **main:** dont ignore caddy ([74e1e8c](https://github.com/snomiao/fbi-proxy/commit/74e1e8c070e08ae31bac498f583f1807b8a20920))
|
|
7
|
+
* **main:** init bun ([9b7baed](https://github.com/snomiao/fbi-proxy/commit/9b7baedf1f80a55cc818f97099cc5c854fda0d9e))
|
|
8
|
+
* **main:** setup ([0a00110](https://github.com/snomiao/fbi-proxy/commit/0a00110e6ace713265b4dbf3980515e77663e8a0))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* add Caddyfile and CLI for proxy server setup with WebSocket support ([8ed37b0](https://github.com/snomiao/fbi-proxy/commit/8ed37b0652a33beae86b2b6c3881534c1bb9b1bc))
|
|
14
|
+
* migrate to semantic-release for automated releases ([b3a5f8a](https://github.com/snomiao/fbi-proxy/commit/b3a5f8a1e2cfc92d7e93a941d15acb43ce896d3f))
|
|
15
|
+
* proxy.rs now reads PROXY_PORT environment variable ([1616790](https://github.com/snomiao/fbi-proxy/commit/1616790c855d49f4f5c78b31022dca6caa6148f3))
|
|
16
|
+
* update Caddyfile to use FBIPROXY_PORT and enhance cli.ts with help options and improved proxy handling ([0de99ff](https://github.com/snomiao/fbi-proxy/commit/0de99ff4e1c0cd15be579ac98f4b19479c320210))
|
|
17
|
+
* update project configuration and dependencies ([ab9d8cf](https://github.com/snomiao/fbi-proxy/commit/ab9d8cfe7cfb200c57df915e7ab4ede3a7b0a703))
|
package/Caddyfile
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
admin off
|
|
3
|
+
# TODO: add ondemand tls endpoint to cli.ts
|
|
4
|
+
# - [Global options (Caddyfile) — Caddy Documentation]( https://caddyserver.com/docs/caddyfile/options#on-demand-tls )
|
|
5
|
+
# make a endpoint to handle /CHECK_TLS?domain=..., and return 200 if domain is valid
|
|
6
|
+
#
|
|
7
|
+
# on_demand_tls {
|
|
8
|
+
# ask http://localhost:{$PROX}/CHECK_TLS
|
|
9
|
+
# }
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
# unwrap all https
|
|
13
|
+
*, *.*, *.*.*, *.*.*.* {
|
|
14
|
+
tls internal {
|
|
15
|
+
on_demand
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
reverse_proxy :{$FBIPROXY_PORT:24306}
|
|
19
|
+
}
|
package/Dockerfile
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Multi-stage Docker build for FBI Proxy
|
|
2
|
+
FROM rust:1.70-alpine AS builder
|
|
3
|
+
|
|
4
|
+
WORKDIR /app
|
|
5
|
+
COPY rs/ ./rs/
|
|
6
|
+
WORKDIR /app/rs
|
|
7
|
+
|
|
8
|
+
# Install build dependencies
|
|
9
|
+
RUN apk add --no-cache musl-dev
|
|
10
|
+
|
|
11
|
+
# Build the proxy
|
|
12
|
+
RUN cargo build --release --target x86_64-unknown-linux-musl
|
|
13
|
+
|
|
14
|
+
# Runtime stage
|
|
15
|
+
FROM node:18-alpine
|
|
16
|
+
|
|
17
|
+
# Install Caddy and Bun
|
|
18
|
+
RUN apk add --no-cache caddy curl bash
|
|
19
|
+
RUN curl -fsSL https://bun.sh/install | bash
|
|
20
|
+
ENV PATH="/root/.bun/bin:$PATH"
|
|
21
|
+
|
|
22
|
+
WORKDIR /app
|
|
23
|
+
|
|
24
|
+
# Copy the built proxy binary
|
|
25
|
+
COPY --from=builder /app/rs/target/x86_64-unknown-linux-musl/release/proxy /app/bin/proxy
|
|
26
|
+
RUN chmod +x /app/bin/proxy
|
|
27
|
+
|
|
28
|
+
# Copy application files
|
|
29
|
+
COPY package.json ./
|
|
30
|
+
COPY src/ ./src/
|
|
31
|
+
COPY Caddyfile ./
|
|
32
|
+
|
|
33
|
+
# Install dependencies
|
|
34
|
+
RUN npm install
|
|
35
|
+
|
|
36
|
+
EXPOSE 24306 80 443
|
|
37
|
+
|
|
38
|
+
CMD ["bun", "src/cli.ts"]
|
package/INSTALL.md
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# FBI Proxy - Installation Guide
|
|
2
|
+
|
|
3
|
+
FBI Proxy now supports multiple installation methods, **no Rust installation required**!
|
|
4
|
+
|
|
5
|
+
## 🚀 Quick Install (Recommended)
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install
|
|
9
|
+
npm start
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
The proxy binary will be automatically downloaded during installation.
|
|
13
|
+
|
|
14
|
+
## 📦 Installation Methods
|
|
15
|
+
|
|
16
|
+
### Method 1: Auto-Download (Default)
|
|
17
|
+
|
|
18
|
+
- **No Rust required** ✅
|
|
19
|
+
- Pre-built binaries downloaded automatically
|
|
20
|
+
- Supports Windows, macOS, and Linux (x64 + ARM64)
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install # Downloads proxy binary automatically
|
|
24
|
+
npm start # Starts the proxy system
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Method 2: Build from Source (Optional)
|
|
28
|
+
|
|
29
|
+
If you have Rust installed and want to build from source:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm run build-proxy # Builds from Rust source
|
|
33
|
+
npm start # Starts the proxy system
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Method 3: Docker (Containerized)
|
|
37
|
+
|
|
38
|
+
For containerized deployment:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
docker build -t fbi-proxy .
|
|
42
|
+
docker run -p 24306:24306 -p 80:80 -p 443:443 fbi-proxy
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## 📋 Available Scripts
|
|
46
|
+
|
|
47
|
+
| Script | Description | Requires Rust |
|
|
48
|
+
| --------------------- | -------------------------------- | ------------- |
|
|
49
|
+
| `npm install` | Auto-setup (download or build) | ❌ No |
|
|
50
|
+
| `npm start` | Start the proxy system | ❌ No |
|
|
51
|
+
| `npm run dev` | Development mode with hot reload | ❌ No |
|
|
52
|
+
| `npm run build-proxy` | Build/download proxy binary | ❌ No |
|
|
53
|
+
| `npm run clean-proxy` | Clean built files | ❌ No |
|
|
54
|
+
|
|
55
|
+
## 🔧 Advanced Scripts (Rust Required)
|
|
56
|
+
|
|
57
|
+
| Script | Description |
|
|
58
|
+
| -------------------------------- | ----------------- |
|
|
59
|
+
| `cd rs && cargo build --release` | Manual Rust build |
|
|
60
|
+
| `cd rs && cargo test` | Run Rust tests |
|
|
61
|
+
| `cd rs && cargo fmt` | Format Rust code |
|
|
62
|
+
|
|
63
|
+
## 🏗️ Build Strategy
|
|
64
|
+
|
|
65
|
+
The build system automatically:
|
|
66
|
+
|
|
67
|
+
1. **First**: Tries to download pre-built binary from GitHub releases
|
|
68
|
+
2. **Fallback**: If Rust is installed, builds from source
|
|
69
|
+
3. **Manual**: Provides instructions if both fail
|
|
70
|
+
|
|
71
|
+
## 🌐 Platform Support
|
|
72
|
+
|
|
73
|
+
| Platform | Architecture | Binary Name | Status |
|
|
74
|
+
| -------- | ------------ | ----------------------- | ------ |
|
|
75
|
+
| Windows | x64 | `proxy-windows-x64.exe` | ✅ |
|
|
76
|
+
| macOS | x64 | `proxy-macos-x64` | ✅ |
|
|
77
|
+
| macOS | ARM64 | `proxy-macos-arm64` | ✅ |
|
|
78
|
+
| Linux | x64 | `proxy-linux-x64` | ✅ |
|
|
79
|
+
| Linux | ARM64 | `proxy-linux-arm64` | ✅ |
|
|
80
|
+
|
|
81
|
+
## 🐳 Docker Usage
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
# Build Docker image
|
|
85
|
+
docker build -t fbi-proxy .
|
|
86
|
+
|
|
87
|
+
# Run container
|
|
88
|
+
docker run -d \
|
|
89
|
+
--name fbi-proxy \
|
|
90
|
+
-p 24306:24306 \
|
|
91
|
+
-p 80:80 \
|
|
92
|
+
-p 443:443 \
|
|
93
|
+
-v $(pwd)/Caddyfile:/app/Caddyfile \
|
|
94
|
+
fbi-proxy
|
|
95
|
+
|
|
96
|
+
# View logs
|
|
97
|
+
docker logs -f fbi-proxy
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## 🔍 Troubleshooting
|
|
101
|
+
|
|
102
|
+
### Binary Not Found
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
npm run build-proxy # Try rebuilding/downloading
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### All Build Methods Failed
|
|
109
|
+
|
|
110
|
+
1. Install Rust: https://rustup.rs/
|
|
111
|
+
2. Build manually:
|
|
112
|
+
```bash
|
|
113
|
+
cd rs
|
|
114
|
+
cargo build --release
|
|
115
|
+
cp target/release/proxy* ../bin/
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Docker Issues
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
# Clean build
|
|
122
|
+
docker build --no-cache -t fbi-proxy .
|
|
123
|
+
|
|
124
|
+
# Check container logs
|
|
125
|
+
docker logs fbi-proxy
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## 🎯 Benefits
|
|
129
|
+
|
|
130
|
+
- ✅ **No Rust Installation Required** for end users
|
|
131
|
+
- ✅ **Cross-Platform Support** (Windows, macOS, Linux)
|
|
132
|
+
- ✅ **Multiple Architectures** (x64, ARM64)
|
|
133
|
+
- ✅ **Automatic Updates** via GitHub releases
|
|
134
|
+
- ✅ **Fallback to Source Build** when needed
|
|
135
|
+
- ✅ **Docker Support** for containerized deployment
|
|
136
|
+
|
|
137
|
+
## 🚦 Quick Start Examples
|
|
138
|
+
|
|
139
|
+
### Development
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
git clone <repo>
|
|
143
|
+
cd fbi-proxy
|
|
144
|
+
npm install # Auto-downloads proxy binary
|
|
145
|
+
npm run dev # Start with hot reload
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Production
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
npm install
|
|
152
|
+
npm start
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Docker Production
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
docker-compose up -d
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
The proxy will automatically handle port encoding (`domain--3000` → `domain:3000`) and forward requests to your local services!
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 snomiao
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/PINGORA_PROXY.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# Pingora-Based Rust Proxy
|
|
2
|
+
|
|
3
|
+
The proxy functionality has been migrated from TypeScript/Bun to Rust using Cloudflare's **Pingora** framework for maximum performance and reliability.
|
|
4
|
+
|
|
5
|
+
## Architecture
|
|
6
|
+
|
|
7
|
+
- **TypeScript (`src/cli.ts`)**: Main entry point that:
|
|
8
|
+
- Checks for Rust and Caddy installation
|
|
9
|
+
- Launches the Rust proxy server
|
|
10
|
+
- Starts Caddy with the appropriate configuration
|
|
11
|
+
- **Rust (`rs/proxy.rs`)**: Ultra high-performance proxy server using Pingora that:
|
|
12
|
+
- Handles HTTP requests with zero-copy forwarding
|
|
13
|
+
- Processes host header port encoding (e.g., `example.com--3000` → `example.com:3000`)
|
|
14
|
+
- Forwards requests to local services with optimal performance
|
|
15
|
+
- Built-in WebSocket support (handled by Pingora)
|
|
16
|
+
- Runs on port 24306
|
|
17
|
+
|
|
18
|
+
## Why Pingora?
|
|
19
|
+
|
|
20
|
+
**Pingora** is Cloudflare's production-grade HTTP proxy framework built in Rust:
|
|
21
|
+
|
|
22
|
+
- ⚡ **Performance**: Used by Cloudflare to handle millions of requests per second
|
|
23
|
+
- 🔒 **Security**: Memory-safe Rust with battle-tested proxy logic
|
|
24
|
+
- 🌐 **WebSocket Support**: Built-in WebSocket proxying capabilities
|
|
25
|
+
- 📊 **Observability**: Advanced logging and metrics
|
|
26
|
+
- 🔧 **Flexibility**: Modular design for custom proxy logic
|
|
27
|
+
- 🚀 **Production Ready**: Powers Cloudflare's edge network
|
|
28
|
+
|
|
29
|
+
## Building
|
|
30
|
+
|
|
31
|
+
### Using npm/bun scripts:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# Build release version
|
|
35
|
+
bun run build-proxy
|
|
36
|
+
|
|
37
|
+
# Build development version
|
|
38
|
+
bun run build-proxy-dev
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Manual build:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
cd rs
|
|
45
|
+
cargo build --release
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Platform-specific build scripts:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# Linux/macOS
|
|
52
|
+
./build-proxy.sh
|
|
53
|
+
|
|
54
|
+
# Windows
|
|
55
|
+
build-proxy.bat
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Dependencies
|
|
59
|
+
|
|
60
|
+
### System Requirements:
|
|
61
|
+
|
|
62
|
+
- Rust (install from https://rustup.rs/)
|
|
63
|
+
- Caddy web server
|
|
64
|
+
- Bun runtime
|
|
65
|
+
|
|
66
|
+
### Rust Dependencies:
|
|
67
|
+
|
|
68
|
+
- `pingora` - Cloudflare's high-performance HTTP proxy framework
|
|
69
|
+
- `async-trait` - Async trait support
|
|
70
|
+
- `regex` - Pattern matching for host processing
|
|
71
|
+
- `env_logger` - Logging infrastructure
|
|
72
|
+
- `tokio` - Async runtime (used by Pingora)
|
|
73
|
+
|
|
74
|
+
## Features
|
|
75
|
+
|
|
76
|
+
- **🚀 Ultra High Performance**: Pingora framework used in Cloudflare production
|
|
77
|
+
- **⚡ Zero-Copy Proxying**: Efficient request/response forwarding
|
|
78
|
+
- **🌐 WebSocket Support**: Built-in WebSocket proxying (no custom implementation needed)
|
|
79
|
+
- **🔧 Port Encoding**: Supports special host header format for port specification
|
|
80
|
+
- **📊 Advanced Logging**: Detailed request/response logging and metrics
|
|
81
|
+
- **🛡️ Error Handling**: Production-grade error handling and recovery
|
|
82
|
+
- **🔄 Hot Reloading**: Development-friendly with auto-restart capabilities
|
|
83
|
+
|
|
84
|
+
## Usage
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# Start the full proxy system
|
|
88
|
+
bun start
|
|
89
|
+
|
|
90
|
+
# Development mode with hot reloading
|
|
91
|
+
bun run dev
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The proxy will:
|
|
95
|
+
|
|
96
|
+
1. Start the Pingora-based Rust proxy server on port 24306
|
|
97
|
+
2. Launch Caddy with the configured Caddyfile
|
|
98
|
+
3. Handle all incoming requests with maximum performance
|
|
99
|
+
4. Automatically handle WebSocket upgrades and forwarding
|
|
100
|
+
|
|
101
|
+
## Proxy Implementation Details
|
|
102
|
+
|
|
103
|
+
The Pingora implementation uses the `ProxyHttp` trait to:
|
|
104
|
+
|
|
105
|
+
1. **Request Filter**: Processes incoming requests, extracts host headers, handles port encoding
|
|
106
|
+
2. **Upstream Peer**: Determines the target upstream server dynamically
|
|
107
|
+
3. **Response Filter**: Modifies response headers (removes content-encoding)
|
|
108
|
+
4. **Logging**: Comprehensive request/response logging with error tracking
|
|
109
|
+
|
|
110
|
+
### Port Encoding Logic
|
|
111
|
+
|
|
112
|
+
```rust
|
|
113
|
+
// Converts: example.com--3000.domain.com -> example.com:3000
|
|
114
|
+
let target_host = port_regex.replace(host_header, ":$1").to_string();
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
This allows encoding port numbers in domain names for proxy routing.
|
|
118
|
+
|
|
119
|
+
## Performance Benefits
|
|
120
|
+
|
|
121
|
+
Compared to the previous Hyper-based implementation:
|
|
122
|
+
|
|
123
|
+
- **🏃♂️ Faster**: Pingora's optimized request processing
|
|
124
|
+
- **💾 Lower Memory**: Better memory management and pooling
|
|
125
|
+
- **🔄 Better WebSocket**: Native WebSocket support without custom forwarding
|
|
126
|
+
- **📈 Scalability**: Handles more concurrent connections
|
|
127
|
+
- **🔧 Maintainability**: Cleaner code with built-in proxy patterns
|