Skip to content

Commit

Permalink
Include docker-compose setup
Browse files Browse the repository at this point in the history
  • Loading branch information
boronine committed Oct 14, 2024
1 parent a128bb0 commit 4f425f5
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/*.tgz
/*.crt
/*.key
/.env
2 changes: 1 addition & 1 deletion Caddyfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mysite.com {
{$TUNNEL_DOMAIN} {
reverse_proxy h2tunnel:80
}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FROM node:22
RUN npm install -g h2tunnel
RUN npm install -g h2tunnel@0.0.1-alpha.3
60 changes: 36 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,65 @@ This is a peculiar workflow for web programmers that allows to expose their loca
to the internet as a public address. Typically you would run your development server on some local port,
then launch a daemon process that will tunnel your traffic to a reverse proxy with a public IP.

## How it works
## Usage

## CLI
### Forward localhost:8000 to example.com:80

Generate `.key` and `.crt` files:
Generate `.key` and `.crt` files. These will be used by both client and server to authenticate each other.

```bash
openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:secp384r1 -days 3650 -nodes -keyout h2tunnel.key -out h2tunnel.crt -subj "/CN=example.com"
```

Local:
On your server (example.com), we will be listening for tunnel connections on port 15001, and providing an HTTP proxy
on port 80. Make sure these are open in your firewall. `--mux-listen-port` can be any available port, it is necessary
to run an HTTP2 multiplexer on localhost.

```bash
h2tunnel server --crt h2tunnel.crt --key h2tunnel.key --tunnel-listen-ip 0.0.0.0 --tunnel-listen-port 15001 --proxy-listen-port 80 --proxy-listen-ip 0.0.0.0 --mux-listen-port=15002
````

On your local machine, we will connect to the tunnel and forward a local HTTP server on port 8000. `--demux-listen-port`
can be any available port, it is necessary to run an HTTP2 demultiplexer on localhost.

```bash
python3 -m http.server # runs on port 8000
h2tunnel client --tunnel-host=localhost --tunnel-port=15001 --local-http-port=8000 --demux-listen-port=15004
# open browser http://localhost:15002
h2tunnel client --key h2tunnel.key --crt h2tunnel.crt --tunnel-host=example.com --tunnel-port=15001 --local-http-port=8000 --demux-listen-port=15004
```

Remote:
### Forward localhost:8000 to example.com:443

```bash
h2tunnel server --tunnel-listen-port=15001 --remote-http-port=15002 --mux-listen-port=15003 --tunnel-listen-ip=127.0.0.1
````
This is the same as the previous example, but with an extra layer: a [Caddy](https://caddyserver.com/) reverse proxy
that will auto-provision TLS certificates for your domain. This is useful if you want to expose an HTTPS server.

## Testing
The client command line is the same as before, but for the server we will use a docker compose setup.

```bash
npm run test
Specify your domain in the `.env` file:

```
TUNNEL_DOMAIN=example.com
```

# Releasing
Push the necessary files to the server:

```bash
npm run build && npm version prerelease --preid=alpha && npm publish
scp Caddyfile .env Dockerfile docker-compose.yml h2tunnel.crt h2tunnel.key example.com:/home/myuser
```

Client:

## WIP IDEAS
Start the server:

```bash
docker compose up
```
SEND_PORT=[int]
SERVER_HOST=[ip_or_domain] # Note: domain relies on DNS
SERVER_
SERVER_CERT_WHITELIST=[base64],[base64],...

## Testing

```bash
npm run test
```

Alt name: portsend.js (with possible portsend.py etc. in the future)
# Releasing

https://github.com/nodejs/node/issues/46152
```bash
npm run build && npm version prerelease --preid=alpha && npm publish
```
7 changes: 6 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ services:
- "443:443/udp"
depends_on:
- h2tunnel
# Use this to provide TUNNEL_DOMAIN
env_file: .env
volumes:
- $PWD/Caddyfile:/etc/caddy/Caddyfile
- /data
Expand All @@ -19,10 +21,13 @@ services:
cap_add:
- NET_ADMIN
build: .
secrets:
- crt
- key
ports:
- "80" # for caddy
- "15001:15001"
command: h2tunnel --crt=/run/secrets/crt --key=/run/secrets/key --tunnel-listen-ip=0.0.0.0 --tunnel-listen-port=15001 --proxy-listen-port=80 --proxy-listen-ip=0.0.0.0 --mux-listen-port=15002
command: h2tunnel server --crt=/run/secrets/crt --key=/run/secrets/key --tunnel-listen-ip=0.0.0.0 --tunnel-listen-port=15001 --proxy-listen-port=80 --proxy-listen-ip=0.0.0.0 --mux-listen-port=15002
secrets:
crt:
file: ./h2tunnel.crt
Expand Down

0 comments on commit 4f425f5

Please sign in to comment.