Skip to content

Commit 2c7baf7

Browse files
committed
Initial commit: simple reverse proxy with authentication
0 parents  commit 2c7baf7

File tree

8 files changed

+528
-0
lines changed

8 files changed

+528
-0
lines changed

.github/workflows/ci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
test:
14+
name: Test
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: dtolnay/rust-toolchain@stable
19+
- run: cargo test --verbose
20+
21+
fmt:
22+
name: Format
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v4
26+
- uses: dtolnay/rust-toolchain@stable
27+
with:
28+
components: rustfmt
29+
- run: cargo fmt --all -- --check
30+
31+
clippy:
32+
name: Clippy
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v4
36+
- uses: dtolnay/rust-toolchain@stable
37+
with:
38+
components: clippy
39+
- run: cargo clippy -- -D warnings

.github/workflows/release.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
name: Build ${{ matrix.target }}
14+
runs-on: ${{ matrix.os }}
15+
strategy:
16+
matrix:
17+
include:
18+
- target: x86_64-unknown-linux-musl
19+
os: ubuntu-latest
20+
- target: aarch64-unknown-linux-musl
21+
os: ubuntu-latest
22+
- target: x86_64-apple-darwin
23+
os: macos-latest
24+
- target: aarch64-apple-darwin
25+
os: macos-latest
26+
27+
steps:
28+
- uses: actions/checkout@v4
29+
30+
- name: Install Rust
31+
uses: dtolnay/rust-toolchain@stable
32+
with:
33+
targets: ${{ matrix.target }}
34+
35+
- name: Install cross-compilation tools
36+
if: matrix.os == 'ubuntu-latest'
37+
run: |
38+
cargo install cross --git https://github.com/cross-rs/cross
39+
40+
- name: Build
41+
run: |
42+
if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then
43+
cross build --release --target ${{ matrix.target }}
44+
else
45+
cargo build --release --target ${{ matrix.target }}
46+
fi
47+
48+
- name: Rename binary
49+
run: |
50+
cp target/${{ matrix.target }}/release/apxy apxy-${{ matrix.target }}
51+
52+
- name: Upload artifacts
53+
uses: actions/upload-artifact@v4
54+
with:
55+
name: apxy-${{ matrix.target }}
56+
path: apxy-${{ matrix.target }}
57+
58+
release:
59+
name: Create Release
60+
needs: build
61+
runs-on: ubuntu-latest
62+
steps:
63+
- uses: actions/checkout@v4
64+
65+
- name: Download artifacts
66+
uses: actions/download-artifact@v4
67+
with:
68+
path: artifacts
69+
70+
- name: Create Release
71+
uses: softprops/action-gh-release@v1
72+
with:
73+
files: artifacts/*/apxy-*
74+
draft: false
75+
prerelease: false
76+
env:
77+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Rust
2+
/target/
3+
**/*.rs.bk
4+
*.pdb
5+
Cargo.lock
6+
7+
# IDE
8+
.vscode/
9+
.idea/
10+
*.swp
11+
*.swo
12+
*~
13+
14+
# OS
15+
.DS_Store
16+
Thumbs.db

Cargo.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[package]
2+
name = "apxy"
3+
version = "0.1.0"
4+
edition = "2021"
5+
authors = ["apxy contributors"]
6+
description = "A simple reverse proxy with URL parameter or header authentication"
7+
license = "MIT"
8+
repository = "https://github.com/YOUR_USERNAME/apxy"
9+
readme = "README.md"
10+
keywords = ["proxy", "reverse-proxy", "authentication"]
11+
categories = ["command-line-utilities", "web-programming"]
12+
13+
[dependencies]
14+
tokio = { version = "1", features = ["full"] }
15+
hyper = { version = "1", features = ["full"] }
16+
hyper-util = { version = "0.1", features = ["full"] }
17+
http-body-util = "0.1"
18+
clap = { version = "4", features = ["derive"] }
19+
tower = "0.4"
20+
21+
[profile.release]
22+
opt-level = "z"
23+
lto = true
24+
codegen-units = 1
25+
panic = "abort"
26+
strip = true

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 apxy contributors
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.

README.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# apxy
2+
3+
A simple, lightweight reverse proxy with URL parameter or header authentication.
4+
5+
## Features
6+
7+
- 🚀 Simple reverse proxy for any web service
8+
- 🔒 Optional authentication via URL parameter or header
9+
- 📦 Zero configuration files needed
10+
- ⚡ Static binary, minimal dependencies
11+
- 🎯 Cross-platform: ARM64, AMD64
12+
13+
## Installation
14+
15+
### Via Cargo
16+
17+
```bash
18+
cargo install apxy
19+
```
20+
21+
### Via curl (Quick Install)
22+
23+
```bash
24+
# Linux/macOS ARM64
25+
curl -L https://github.com/YOUR_USERNAME/apxy/releases/latest/download/apxy-aarch64-unknown-linux-musl -o apxy
26+
chmod +x apxy
27+
sudo mv apxy /usr/local/bin/
28+
29+
# Linux AMD64
30+
curl -L https://github.com/YOUR_USERNAME/apxy/releases/latest/download/apxy-x86_64-unknown-linux-musl -o apxy
31+
chmod +x apxy
32+
sudo mv apxy /usr/local/bin/
33+
34+
# macOS ARM64
35+
curl -L https://github.com/YOUR_USERNAME/apxy/releases/latest/download/apxy-aarch64-apple-darwin -o apxy
36+
chmod +x apxy
37+
sudo mv apxy /usr/local/bin/
38+
39+
# macOS AMD64
40+
curl -L https://github.com/YOUR_USERNAME/apxy/releases/latest/download/apxy-x86_64-apple-darwin -o apxy
41+
chmod +x apxy
42+
sudo mv apxy /usr/local/bin/
43+
```
44+
45+
## Usage
46+
47+
### Basic Proxy (No Authentication)
48+
49+
```bash
50+
apxy --target http://localhost:3000
51+
```
52+
53+
This will start a proxy on port 8080 that forwards all requests to `http://localhost:3000`.
54+
55+
### With Authentication
56+
57+
```bash
58+
apxy --target http://localhost:3000 --auth-token mysecrettoken
59+
```
60+
61+
Now clients must provide the token either as:
62+
63+
**URL Parameter:**
64+
65+
```bash
66+
curl http://localhost:8080/api/data?token=mysecrettoken
67+
```
68+
69+
**Header:**
70+
71+
```bash
72+
curl -H "X-Auth-Token: mysecrettoken" http://localhost:8080/api/data
73+
```
74+
75+
### Custom Port
76+
77+
```bash
78+
apxy --port 9000 --target http://localhost:3000
79+
```
80+
81+
### Full Example
82+
83+
```bash
84+
apxy \
85+
--port 8080 \
86+
--target http://localhost:3000 \
87+
--auth-token supersecret123
88+
```
89+
90+
## Command Line Options
91+
92+
```
93+
Options:
94+
-p, --port <PORT> Port to listen on [default: 8080]
95+
-t, --target <TARGET> Target URL to proxy to
96+
-a, --auth-token <AUTH_TOKEN> Authentication token
97+
-h, --help Print help
98+
-V, --version Print version
99+
```
100+
101+
## Use Cases
102+
103+
- Add authentication layer to existing services
104+
- Quick reverse proxy for development
105+
- Expose local services securely
106+
- Simple API gateway
107+
108+
## Building from Source
109+
110+
```bash
111+
git clone https://github.com/YOUR_USERNAME/apxy
112+
cd apxy
113+
cargo build --release
114+
```
115+
116+
The binary will be at `target/release/apxy`.
117+
118+
## License
119+
120+
MIT

install.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# apxy installer script
5+
6+
REPO="talkincode/apxy"
7+
INSTALL_DIR="/usr/local/bin"
8+
BINARY_NAME="apxy"
9+
10+
# Detect OS and architecture
11+
detect_platform() {
12+
local os="$(uname -s)"
13+
local arch="$(uname -m)"
14+
15+
case "$os" in
16+
Linux*)
17+
case "$arch" in
18+
x86_64) echo "x86_64-unknown-linux-musl" ;;
19+
aarch64|arm64) echo "aarch64-unknown-linux-musl" ;;
20+
*) echo "Unsupported architecture: $arch" >&2; exit 1 ;;
21+
esac
22+
;;
23+
Darwin*)
24+
case "$arch" in
25+
x86_64) echo "x86_64-apple-darwin" ;;
26+
arm64) echo "aarch64-apple-darwin" ;;
27+
*) echo "Unsupported architecture: $arch" >&2; exit 1 ;;
28+
esac
29+
;;
30+
*)
31+
echo "Unsupported OS: $os" >&2
32+
exit 1
33+
;;
34+
esac
35+
}
36+
37+
main() {
38+
local platform="$(detect_platform)"
39+
local download_url="https://github.com/${REPO}/releases/latest/download/apxy-${platform}"
40+
41+
echo "📦 Downloading apxy for ${platform}..."
42+
43+
local tmp_file="$(mktemp)"
44+
45+
if command -v curl >/dev/null 2>&1; then
46+
curl -fsSL "$download_url" -o "$tmp_file"
47+
elif command -v wget >/dev/null 2>&1; then
48+
wget -q "$download_url" -O "$tmp_file"
49+
else
50+
echo "Error: curl or wget is required" >&2
51+
exit 1
52+
fi
53+
54+
chmod +x "$tmp_file"
55+
56+
echo "🔧 Installing to ${INSTALL_DIR}/${BINARY_NAME}..."
57+
58+
if [ -w "$INSTALL_DIR" ]; then
59+
mv "$tmp_file" "${INSTALL_DIR}/${BINARY_NAME}"
60+
else
61+
sudo mv "$tmp_file" "${INSTALL_DIR}/${BINARY_NAME}"
62+
fi
63+
64+
echo "✅ apxy installed successfully!"
65+
echo ""
66+
echo "Usage: apxy --target http://localhost:3000 --auth-token mysecret"
67+
echo "For more info: apxy --help"
68+
}
69+
70+
main "$@"

0 commit comments

Comments
 (0)