-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathllms.txt
More file actions
128 lines (95 loc) · 3.9 KB
/
Copy pathllms.txt
File metadata and controls
128 lines (95 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# hsync
> Reverse-proxy and TCP tunnel client for Node.js AND browsers. Share local servers as public URLs, tunnel arbitrary TCP between clients via WebSocket. Works in-browser too.
## What It Does
1. **Public URLs for local servers** - Like ngrok but self-hosted
2. **TCP tunneling** - Forward any TCP port between two hsync clients
3. **Browser support** - Works in browsers via WebSocket, not just Node.js
4. **MQTT integration** - Pub/sub messaging between connected clients
## Installation
```bash
npm install -g hsync
```
Or use in browser:
```html
<script src="https://cdn.jsdelivr.net/npm/hsync/dist/hsync.min.js"></script>
```
## Quick Start
### Share a local webserver
```bash
# Share localhost:3000 as a public URL
hsync -p 3000
```
### Programmatic usage (Node.js)
```javascript
import { hsync } from 'hsync';
const connection = await hsync({
server: 'wss://your-hsync-server.com/_hs',
secret: 'your-secret',
name: 'myapp',
local: 'http://localhost:3000'
});
console.log('Public URL:', connection.publicUrl);
```
### Browser usage
```javascript
const connection = await hsync.dynamicConnect();
// Get a temporary public URL without config
```
## Configuration
| Flag | Env Variable | Description |
|------|-------------|-------------|
| `-p, --port` | `PORT` | Local webserver port |
| `-s, --hsync-server` | `HSYNC_SERVER` | Server URL (wss://...) |
| `-hs, --hsync-secret` | `HSYNC_SECRET` | Authentication secret |
| `-d, --dynamic-host` | `HSYNC_DYNAMIC_HOST` | Get temp URL without secret |
### TCP Tunneling
```bash
# Listen locally on port 2222, forward to remote host:22
hsync --listener-local-port 2222 --listener-target-host remote.server.com --listener-target-port 22
```
### Relay mode (remote → local)
```bash
# Accept connections on server port 8080, forward to local port 3000
hsync --relay-inbound-port 8080 --relay-target-host localhost --relay-target-port 3000
```
## Key Exports
```javascript
import { hsync } from 'hsync'; // Main connection function
import { hsync } from 'hsync/web'; // Browser-specific (smaller)
import { hsync } from 'hsync/node'; // Node.js-specific
import { getConfig } from 'hsync/config'; // Configuration utilities
```
## Architecture
```
┌─────────────────┐
│ hsync-server │
│ (public URL) │
└────────┬────────┘
│ WebSocket
┌─────────────────┼─────────────────┐
│ │ │
┌──────▼──────┐ ┌──────▼──────┐ ┌──────▼──────┐
│ hsync (Node)│ │hsync (Browser)│ │ hsync (Node)│
│ localhost:X │ │ Web App │ │ localhost:Y │
└─────────────┘ └───────────────┘ └─────────────┘
```
## Use Cases
1. **Development** - Share local dev server with teammates
2. **IoT** - Connect devices behind NAT without port forwarding
3. **Browser P2P** - Connect browsers via WebSocket relay
4. **Remote access** - SSH through firewall via TCP tunnel
5. **Webhooks** - Receive webhooks on local machine
## File Structure
| File | Purpose |
|------|---------|
| `hsync.js` | Node.js client implementation |
| `hsync-web.js` | Browser client (WebSocket only) |
| `cli.js` | Command-line interface |
| `connection.js` | Connection management |
| `config.js` | Configuration handling |
| `lib/` | Internal utilities |
## Related Projects
- [hsync-server](https://github.com/monteslu/hsync-server) - The server component
- [rawr](https://github.com/iceddev/rawr) - JSON-RPC over any transport (used internally)
## License
ISC