Skip to content

Commit 3f6cfc4

Browse files
authored
Merge pull request #1 from cube-root/optimized
Optimized
2 parents a327ab7 + d8939e2 commit 3f6cfc4

25 files changed

Lines changed: 5668 additions & 1584 deletions

.env.example

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
# ProxyHub Configuration
22

3-
# Server Configuration
4-
CONNECTION_TIMEOUT_MINUTES=30 # Server-side connection timeout in minutes (0 to disable)
5-
SOCKET_URL=https://connect.proxyhub.cloud
6-
SOCKET_PATH=/socket.io
3+
# Server port
4+
PORT=4000
5+
6+
# Base domain for tunnel URLs
7+
# Tunnel URLs will be: https://{tunnel-id}.{BASE_DOMAIN}
8+
# Example: https://a1b2c3d4e5f6.proxyhub.cloud
79
BASE_DOMAIN=proxyhub.cloud
10+
11+
# Protocol for generated URLs
812
PROTOCOL=https
913

14+
# Socket.io path
15+
SOCKET_PATH=/socket.io
16+
17+
# Server-side connection timeout in minutes (0 to disable)
18+
CONNECTION_TIMEOUT_MINUTES=30
19+
20+
# Client configuration
21+
SOCKET_URL=https://connect.proxyhub.cloud
22+
1023
# Pricing Plan Examples:
1124
# Free tier: CONNECTION_TIMEOUT_MINUTES=5 # 5 minute sessions
12-
# Basic tier: CONNECTION_TIMEOUT_MINUTES=30 # 30 minute sessions
25+
# Basic tier: CONNECTION_TIMEOUT_MINUTES=30 # 30 minute sessions
1326
# Pro tier: CONNECTION_TIMEOUT_MINUTES=120 # 2 hour sessions
14-
# Premium tier: CONNECTION_TIMEOUT_MINUTES=0 # Unlimited sessions
27+
# Premium tier: CONNECTION_TIMEOUT_MINUTES=0 # Unlimited sessions
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Release Server Docker Image
2+
3+
on:
4+
push:
5+
tags:
6+
- 'server-v*'
7+
8+
permissions:
9+
contents: read
10+
packages: write
11+
12+
jobs:
13+
release:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Docker Buildx
20+
uses: docker/setup-buildx-action@v3
21+
22+
- name: Log in to GitHub Container Registry
23+
uses: docker/login-action@v3
24+
with:
25+
registry: ghcr.io
26+
username: ${{ github.actor }}
27+
password: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: Extract version from tag
30+
id: version
31+
run: echo "VERSION=${GITHUB_REF_NAME#server-v}" >> "$GITHUB_OUTPUT"
32+
33+
- name: Docker metadata
34+
id: meta
35+
uses: docker/metadata-action@v5
36+
with:
37+
images: ghcr.io/${{ github.repository }}/server
38+
tags: |
39+
type=semver,pattern={{version}},value=${{ steps.version.outputs.VERSION }}
40+
type=semver,pattern={{major}}.{{minor}},value=${{ steps.version.outputs.VERSION }}
41+
type=semver,pattern={{major}},value=${{ steps.version.outputs.VERSION }}
42+
type=raw,value=latest
43+
44+
- name: Build and push Docker image
45+
uses: docker/build-push-action@v5
46+
with:
47+
context: ./packages/server
48+
file: ./packages/server/dockerfile
49+
push: true
50+
tags: ${{ steps.meta.outputs.tags }}
51+
labels: ${{ steps.meta.outputs.labels }}
52+
cache-from: type=gha
53+
cache-to: type=gha,mode=max

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) 2024 Abhijith V
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.

Makefile

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# ProxyHub Development Makefile
2+
3+
.PHONY: mock-api client server install dev clean help
4+
.PHONY: docker-build docker-up docker-down docker-logs docker-restart
5+
6+
# Default target
7+
help:
8+
@echo "ProxyHub Development Commands"
9+
@echo ""
10+
@echo "Local Development:"
11+
@echo " make mock-api - Start mock API server on port 3000"
12+
@echo " make client - Start ProxyHub client (connects to port 3000)"
13+
@echo " make client-debug - Start client with debug mode"
14+
@echo " make server - Start ProxyHub server"
15+
@echo " make install - Install dependencies for all packages"
16+
@echo " make clean - Clean node_modules"
17+
@echo ""
18+
@echo "Docker:"
19+
@echo " make docker-build - Build Docker image"
20+
@echo " make docker-up - Start server with Docker Compose"
21+
@echo " make docker-down - Stop Docker containers"
22+
@echo " make docker-logs - View Docker logs"
23+
@echo " make docker-restart - Rebuild and restart containers"
24+
@echo ""
25+
26+
# Start mock API server using always-true
27+
mock-api:
28+
npx always-true
29+
30+
# Start ProxyHub client pointing to mock API on port 3000
31+
client:
32+
cd packages/client && npm run dev -- -p 3000
33+
34+
# Start ProxyHub client with debug mode
35+
client-debug:
36+
cd packages/client && npm run dev -- -p 3000 -d
37+
38+
# Start ProxyHub server
39+
server:
40+
cd packages/server && npm run dev
41+
42+
# Install dependencies
43+
install:
44+
npm install
45+
cd packages/client && npm install
46+
cd packages/server && npm install
47+
48+
# Clean node_modules
49+
clean:
50+
rm -rf node_modules
51+
rm -rf packages/client/node_modules
52+
rm -rf packages/server/node_modules
53+
54+
# Docker commands
55+
docker-build:
56+
docker compose build
57+
58+
docker-up:
59+
docker compose up -d
60+
61+
docker-down:
62+
docker compose down
63+
64+
docker-logs:
65+
docker compose logs -f
66+
67+
docker-restart:
68+
docker compose up -d --build

README.md

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
# ProxyHub
2+
3+
[![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
4+
[![Node.js](https://img.shields.io/badge/Node.js-%3E%3D18.0.0-brightgreen)](https://nodejs.org/)
5+
[![npm](https://img.shields.io/npm/v/@proxyhub/client)](https://www.npmjs.com/package/@proxyhub/client)
6+
7+
Expose localhost to the internet. Self-hostable ngrok alternative.
8+
9+
## Quick Start
10+
11+
```bash
12+
npx @proxyhub/client -p 3000
13+
```
14+
15+
That's it! Your local server running on port 3000 is now accessible from the internet.
16+
17+
## Features
18+
19+
- **Instant Setup** - No account required, just run one command
20+
- **Token Protection** - Secure your tunnels with authentication tokens
21+
- **Self-Hostable** - Run your own ProxyHub server
22+
- **Session Timeouts** - Configurable session duration limits
23+
- **WebSocket Support** - Full duplex communication via Socket.IO
24+
25+
## Installation
26+
27+
### Using npx (no install)
28+
29+
```bash
30+
npx @proxyhub/client -p <port>
31+
```
32+
33+
### Global install
34+
35+
```bash
36+
npm install -g @proxyhub/client
37+
proxyhub -p <port>
38+
```
39+
40+
## Usage
41+
42+
### Basic Usage
43+
44+
```bash
45+
# Expose local port 3000
46+
proxyhub -p 3000
47+
48+
# With debug output
49+
proxyhub -p 3000 --debug
50+
```
51+
52+
### Token Protection
53+
54+
Secure your tunnel so only requests with the correct token can access it:
55+
56+
```bash
57+
# Using CLI flag
58+
proxyhub -p 3000 --token mysecrettoken
59+
60+
# Using environment variable
61+
PROXYHUB_TOKEN=mysecrettoken proxyhub -p 3000
62+
```
63+
64+
When token protection is enabled, requests must include the `X-Proxy-Token` header:
65+
66+
```bash
67+
curl -H "X-Proxy-Token: mysecrettoken" https://your-tunnel.proxyhub.cloud/
68+
```
69+
70+
### CLI Options
71+
72+
| Option | Description |
73+
|--------|-------------|
74+
| `-p, --port <port>` | Port number to proxy (required) |
75+
| `-t, --token <token>` | Token for tunnel protection |
76+
| `-d, --debug` | Enable debug mode |
77+
| `-V, --version` | Output version number |
78+
| `-h, --help` | Display help |
79+
80+
## Self-Hosting
81+
82+
### Docker (Recommended)
83+
84+
```bash
85+
docker run -d \
86+
-p 4000:4000 \
87+
-e BASE_DOMAIN=your-domain.com \
88+
-e PROTOCOL=https \
89+
-e CONNECTION_TIMEOUT_MINUTES=30 \
90+
ghcr.io/cube-root/proxyhub-server:latest
91+
```
92+
93+
### Docker Compose
94+
95+
```yaml
96+
services:
97+
server:
98+
build:
99+
context: ./packages/server
100+
dockerfile: Dockerfile
101+
container_name: proxyhub-server
102+
restart: unless-stopped
103+
ports:
104+
- "4000:4000"
105+
environment:
106+
- PORT=4000
107+
- BASE_DOMAIN=your-domain.com
108+
- PROTOCOL=https
109+
- SOCKET_PATH=/socket.io
110+
- CONNECTION_TIMEOUT_MINUTES=30
111+
```
112+
113+
### Connect Client to Self-Hosted Server
114+
115+
```bash
116+
SOCKET_URL=https://your-server.com proxyhub -p 3000
117+
```
118+
119+
## One-Click Deploy
120+
121+
Deploy your own ProxyHub server with one click:
122+
123+
[![Deploy to DO](https://www.deploytodo.com/do-btn-blue.svg)](https://cloud.digitalocean.com/apps/new?repo=https://github.com/cube-root/proxyhub/tree/main)
124+
125+
[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/template/proxyhub)
126+
127+
[![Deploy to Render](https://render.com/images/deploy-to-render-button.svg)](https://render.com/deploy?repo=https://github.com/cube-root/proxyhub)
128+
129+
## Environment Variables
130+
131+
### Server
132+
133+
| Variable | Default | Description |
134+
|----------|---------|-------------|
135+
| `PORT` | `4000` | Server port |
136+
| `BASE_DOMAIN` | `proxyhub.cloud` | Base domain for tunnel URLs |
137+
| `PROTOCOL` | `https` | Protocol for generated URLs |
138+
| `SOCKET_PATH` | `/socket.io` | Socket.IO path |
139+
| `CONNECTION_TIMEOUT_MINUTES` | `30` | Session timeout (0 = unlimited) |
140+
141+
### Client
142+
143+
| Variable | Default | Description |
144+
|----------|---------|-------------|
145+
| `SOCKET_URL` | `https://connect.proxyhub.cloud` | ProxyHub server URL |
146+
| `PROXYHUB_TOKEN` | - | Token for tunnel protection |
147+
148+
## How It Works
149+
150+
1. Client connects to ProxyHub server via WebSocket
151+
2. Server generates a unique tunnel URL (e.g., `https://abc123.proxyhub.cloud`)
152+
3. Incoming HTTP requests to the tunnel URL are forwarded to the client
153+
4. Client proxies requests to your local server and streams responses back
154+
155+
```
156+
Internet Request Your Local Server
157+
| ^
158+
v |
159+
ProxyHub Server <--WebSocket--> ProxyHub Client
160+
(proxyhub.cloud) (your machine)
161+
```
162+
163+
## Development
164+
165+
```bash
166+
# Clone the repository
167+
git clone https://github.com/cube-root/proxyhub.git
168+
cd proxyhub
169+
170+
# Install dependencies
171+
npm install
172+
173+
# Build all packages
174+
npm run build
175+
176+
# Run server locally
177+
cd packages/server && npm run dev
178+
179+
# Run client (in another terminal)
180+
cd packages/client && npm run dev -- -p 3000
181+
```
182+
183+
## License
184+
185+
[MIT](LICENSE) - Copyright (c) 2024 Abhijith V

docker-compose.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
services:
2+
server:
3+
build:
4+
context: ./packages/server
5+
dockerfile: Dockerfile
6+
container_name: proxyhub-server
7+
restart: unless-stopped
8+
ports:
9+
- "4000:4000"
10+
environment:
11+
- PORT=4000
12+
- BASE_DOMAIN=${BASE_DOMAIN:-proxyhub.cloud}
13+
- PROTOCOL=${PROTOCOL:-https}
14+
- SOCKET_PATH=${SOCKET_PATH:-/socket.io}
15+
- CONNECTION_TIMEOUT_MINUTES=${CONNECTION_TIMEOUT_MINUTES:-30}
16+
healthcheck:
17+
test: ["CMD", "wget", "-q", "--spider", "http://localhost:4000/"]
18+
interval: 30s
19+
timeout: 10s
20+
retries: 3
21+
start_period: 10s

0 commit comments

Comments
 (0)