@cjwddz/mirror 1.1.0 → 2.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/README.md +154 -256
- package/dist/cli/cli-commands.d.ts +30 -0
- package/dist/cli/cli-commands.d.ts.map +1 -0
- package/dist/cli/cli-commands.js +391 -0
- package/dist/cli/cli-commands.js.map +1 -0
- package/dist/cli/client.d.ts +19 -0
- package/dist/cli/client.d.ts.map +1 -0
- package/dist/cli/client.js +107 -0
- package/dist/cli/client.js.map +1 -0
- package/dist/cli/index-new.d.ts +6 -0
- package/dist/cli/index-new.d.ts.map +1 -0
- package/dist/cli/index-new.js +116 -0
- package/dist/cli/index-new.js.map +1 -0
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +100 -41
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/server.d.ts +19 -0
- package/dist/cli/server.d.ts.map +1 -0
- package/dist/cli/server.js +77 -0
- package/dist/cli/server.js.map +1 -0
- package/dist/core/http-tunnel-client.d.ts +64 -0
- package/dist/core/http-tunnel-client.d.ts.map +1 -0
- package/dist/core/http-tunnel-client.js +315 -0
- package/dist/core/http-tunnel-client.js.map +1 -0
- package/dist/core/http-tunnel-protocol.d.ts +104 -0
- package/dist/core/http-tunnel-protocol.d.ts.map +1 -0
- package/dist/core/http-tunnel-protocol.js +29 -0
- package/dist/core/http-tunnel-protocol.js.map +1 -0
- package/dist/core/http-tunnel-server.d.ts +79 -0
- package/dist/core/http-tunnel-server.d.ts.map +1 -0
- package/dist/core/http-tunnel-server.js +375 -0
- package/dist/core/http-tunnel-server.js.map +1 -0
- package/dist/core/rule-manager.d.ts +71 -0
- package/dist/core/rule-manager.d.ts.map +1 -0
- package/dist/core/rule-manager.js +165 -0
- package/dist/core/rule-manager.js.map +1 -0
- package/dist/index.d.ts +4 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -8
- package/dist/index.js.map +1 -1
- package/package.json +14 -10
- package/dist/cli/exec.d.ts +0 -9
- package/dist/cli/exec.d.ts.map +0 -1
- package/dist/cli/exec.js +0 -32
- package/dist/cli/exec.js.map +0 -1
- package/dist/cli/host-impl.d.ts +0 -58
- package/dist/cli/host-impl.d.ts.map +0 -1
- package/dist/cli/host-impl.js +0 -547
- package/dist/cli/host-impl.js.map +0 -1
- package/dist/cli/host.d.ts +0 -9
- package/dist/cli/host.d.ts.map +0 -1
- package/dist/cli/host.js +0 -57
- package/dist/cli/host.js.map +0 -1
- package/dist/cli/link.d.ts +0 -10
- package/dist/cli/link.d.ts.map +0 -1
- package/dist/cli/link.js +0 -105
- package/dist/cli/link.js.map +0 -1
- package/dist/cli/logs.d.ts +0 -8
- package/dist/cli/logs.d.ts.map +0 -1
- package/dist/cli/logs.js +0 -48
- package/dist/cli/logs.js.map +0 -1
- package/dist/cli/shell.d.ts +0 -6
- package/dist/cli/shell.d.ts.map +0 -1
- package/dist/cli/shell.js +0 -53
- package/dist/cli/shell.js.map +0 -1
- package/dist/cli/status.d.ts +0 -6
- package/dist/cli/status.d.ts.map +0 -1
- package/dist/cli/status.js +0 -33
- package/dist/cli/status.js.map +0 -1
- package/dist/cli/stop.d.ts +0 -6
- package/dist/cli/stop.d.ts.map +0 -1
- package/dist/cli/stop.js +0 -18
- package/dist/cli/stop.js.map +0 -1
- package/dist/cli/ui/MirrorUI.d.ts +0 -22
- package/dist/cli/ui/MirrorUI.d.ts.map +0 -1
- package/dist/cli/ui/MirrorUI.js +0 -71
- package/dist/cli/ui/MirrorUI.js.map +0 -1
- package/dist/cli/ui/interactive-terminal.d.ts +0 -3
- package/dist/cli/ui/interactive-terminal.d.ts.map +0 -1
- package/dist/cli/ui/interactive-terminal.js +0 -150
- package/dist/cli/ui/interactive-terminal.js.map +0 -1
- package/dist/cli/watch.d.ts +0 -6
- package/dist/cli/watch.d.ts.map +0 -1
- package/dist/cli/watch.js +0 -29
- package/dist/cli/watch.js.map +0 -1
- package/dist/core/daemon.d.ts +0 -154
- package/dist/core/daemon.d.ts.map +0 -1
- package/dist/core/daemon.js +0 -590
- package/dist/core/daemon.js.map +0 -1
- package/dist/core/process-manager.d.ts +0 -19
- package/dist/core/process-manager.d.ts.map +0 -1
- package/dist/core/process-manager.js +0 -76
- package/dist/core/process-manager.js.map +0 -1
- package/dist/transport/pty.d.ts +0 -7
- package/dist/transport/pty.d.ts.map +0 -1
- package/dist/transport/pty.js +0 -26
- package/dist/transport/pty.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
# Mirror
|
|
1
|
+
# Mirror - HTTP 隧道工具
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
将本地服务暴露到公网,支持多服务代理。
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 特性
|
|
6
6
|
|
|
7
|
-
- ✅
|
|
8
|
-
- ✅
|
|
9
|
-
- ✅
|
|
10
|
-
- ✅
|
|
11
|
-
- ✅
|
|
12
|
-
- ✅
|
|
7
|
+
- ✅ 支持多个本地服务同时代理
|
|
8
|
+
- ✅ 基于路径长度的优先级匹配(路径越长优先级越高)
|
|
9
|
+
- ✅ 规则持久化存储
|
|
10
|
+
- ✅ Token 认证
|
|
11
|
+
- ✅ 单客户端连接(新连接自动踢出旧连接)
|
|
12
|
+
- ✅ 支持 WebSocket 协议
|
|
13
13
|
|
|
14
14
|
## 安装
|
|
15
15
|
|
|
@@ -17,327 +17,225 @@
|
|
|
17
17
|
npm install -g @cjwddz/mirror
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
##
|
|
20
|
+
## 快速开始
|
|
21
21
|
|
|
22
|
-
### 1.
|
|
22
|
+
### 1. 启动服务端
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
mirror host --port 7331
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
或者指定 token:
|
|
24
|
+
在公网服务器上运行:
|
|
29
25
|
|
|
30
26
|
```bash
|
|
31
|
-
mirror
|
|
27
|
+
mirror server -p 80 -t 7332 --token your-token
|
|
32
28
|
```
|
|
33
29
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
-
|
|
37
|
-
- `--
|
|
38
|
-
- `--
|
|
39
|
-
- `--token <token>`: 指定 session token(不指定则自动生成)
|
|
30
|
+
参数说明:
|
|
31
|
+
- `-p, --port`: HTTP 服务端口(默认 80)
|
|
32
|
+
- `-t, --tunnel-port`: WebSocket 隧道端口(默认 7332)
|
|
33
|
+
- `--host`: 监听地址(默认 0.0.0.0)
|
|
34
|
+
- `--token`: 认证令牌(可选)
|
|
40
35
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
```
|
|
44
|
-
Mirror host started
|
|
45
|
-
Listening on :7331
|
|
46
|
-
|
|
47
|
-
Connect using:
|
|
48
|
-
mirror link 192.168.1.100:7331?token=KJ82mZpX...
|
|
49
|
-
```
|
|
36
|
+
### 2. 添加代理规则
|
|
50
37
|
|
|
51
|
-
|
|
38
|
+
在本地机器上添加规则:
|
|
52
39
|
|
|
53
|
-
|
|
40
|
+
```bash
|
|
41
|
+
# 添加 API 规则(路径较长,优先级高)
|
|
42
|
+
mirror add example.com/api localhost:3001
|
|
54
43
|
|
|
55
|
-
|
|
44
|
+
# 添加用户 API 规则(路径最长,优先级最高)
|
|
45
|
+
mirror add example.com/api/users localhost:3002
|
|
56
46
|
|
|
57
|
-
|
|
58
|
-
mirror
|
|
47
|
+
# 添加前端规则(根路径,优先级低)
|
|
48
|
+
mirror add example.com localhost:5173
|
|
59
49
|
```
|
|
60
50
|
|
|
61
|
-
|
|
51
|
+
### 3. 连接服务端
|
|
62
52
|
|
|
63
53
|
```bash
|
|
64
|
-
|
|
65
|
-
mirror link ws://mirror.example.com?token=KJ82mZpX...
|
|
66
|
-
|
|
67
|
-
# HTTPS (wss://)
|
|
68
|
-
mirror link wss://mirror.example.com?token=KJ82mZpX...
|
|
54
|
+
mirror link mirror.tri-bank.online --token your-token
|
|
69
55
|
```
|
|
70
56
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
- 格式:`[ws://|wss://]host[:port]?token=xxx`
|
|
74
|
-
- `ws://` 或 `wss://` 协议前缀可选(默认 `ws://`)
|
|
75
|
-
- `port` 可选,如果使用反向代理可以不指定端口
|
|
76
|
-
- `token` 必需,用于身份验证
|
|
77
|
-
|
|
78
|
-
连接成功后:
|
|
79
|
-
|
|
80
|
-
1. 自动进行全量文件同步
|
|
81
|
-
2. 启动文件监听(增量同步)
|
|
82
|
-
3. 进入交互式终端
|
|
83
|
-
|
|
84
|
-
在交互式终端中输入命令,命令会在远程服务器的工作空间中执行。
|
|
85
|
-
|
|
86
|
-
输入 `exit` 或 `quit` 退出。
|
|
57
|
+
连接后,规则会自动同步到服务端。
|
|
87
58
|
|
|
88
|
-
|
|
59
|
+
### 4. 查看状态
|
|
89
60
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
- `EMPTY`: 无 client 连接
|
|
95
|
-
- `SYNCING`: 初始全量文件同步中
|
|
96
|
-
- `READY`: 就绪状态(可执行命令,可同步文件)
|
|
97
|
-
|
|
98
|
-
**改进说明:**
|
|
99
|
-
|
|
100
|
-
- 移除了 `RUNNING` 状态,使用独立标志位跟踪命令执行
|
|
101
|
-
- 文件同步和命令执行完全解耦,互不干扰
|
|
102
|
-
- 解决了长时间运行命令时文件同步卡死的问题
|
|
61
|
+
```bash
|
|
62
|
+
mirror status
|
|
63
|
+
```
|
|
103
64
|
|
|
104
|
-
|
|
65
|
+
输出示例:
|
|
105
66
|
|
|
106
|
-
|
|
107
|
-
-
|
|
108
|
-
|
|
109
|
-
- host 仅在 `exec.version === currentVersion` 时允许执行
|
|
67
|
+
```
|
|
68
|
+
Mirror - Connection Status
|
|
69
|
+
==========================
|
|
110
70
|
|
|
111
|
-
|
|
71
|
+
✓ Mirror client is running
|
|
72
|
+
PID: 12345
|
|
112
73
|
|
|
113
|
-
|
|
114
|
-
-
|
|
115
|
-
|
|
116
|
-
- 使用原子写入保证文件一致性
|
|
117
|
-
- 不再使用 pending 队列机制
|
|
74
|
+
Server Configuration:
|
|
75
|
+
Server: mirror.tri-bank.online
|
|
76
|
+
Token: your-toke...
|
|
118
77
|
|
|
119
|
-
|
|
78
|
+
Proxy Rules (3 configured):
|
|
79
|
+
[3] example.com/api/users -> localhost:3002 (高)
|
|
80
|
+
[1] example.com/api -> localhost:3001 (高)
|
|
81
|
+
[2] example.com/ -> localhost:5173 (低)
|
|
82
|
+
```
|
|
120
83
|
|
|
121
|
-
|
|
122
|
-
- ✅ 文件变更实时生效,开发体验更流畅
|
|
123
|
-
- ✅ 类似本地开发,文件保存后立即可用
|
|
84
|
+
### 5. 查看规则
|
|
124
85
|
|
|
125
|
-
|
|
86
|
+
```bash
|
|
87
|
+
mirror list
|
|
88
|
+
```
|
|
126
89
|
|
|
127
|
-
|
|
128
|
-
- 命令执行在独立的进程组中
|
|
129
|
-
- 断开连接时自动清理所有进程
|
|
90
|
+
输出示例:
|
|
130
91
|
|
|
131
|
-
|
|
92
|
+
```
|
|
93
|
+
Mirror - Proxy Rules
|
|
94
|
+
====================
|
|
132
95
|
|
|
133
|
-
|
|
96
|
+
Total: 3 rule(s)
|
|
134
97
|
|
|
135
|
-
|
|
98
|
+
[3] example.com/api/users -> localhost:3002
|
|
99
|
+
Priority: 高(路径规则)
|
|
100
|
+
Created: 2/18/2026, 11:57:20 AM
|
|
136
101
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
server_name mirror.example.com;
|
|
102
|
+
[1] example.com/api -> localhost:3001
|
|
103
|
+
Priority: 高(路径规则)
|
|
104
|
+
Created: 2/18/2026, 11:57:14 AM
|
|
141
105
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
106
|
+
[2] example.com/ -> localhost:5173
|
|
107
|
+
Priority: 低(域名规则)
|
|
108
|
+
Created: 2/18/2026, 11:57:17 AM
|
|
109
|
+
```
|
|
145
110
|
|
|
146
|
-
|
|
147
|
-
proxy_set_header Upgrade $http_upgrade;
|
|
148
|
-
proxy_set_header Connection "upgrade";
|
|
111
|
+
### 6. 删除规则
|
|
149
112
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
154
|
-
proxy_set_header X-Forwarded-Proto $scheme;
|
|
113
|
+
```bash
|
|
114
|
+
# 删除指定规则
|
|
115
|
+
mirror remove 1
|
|
155
116
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
proxy_send_timeout 7d;
|
|
159
|
-
proxy_read_timeout 7d;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
117
|
+
# 删除所有规则
|
|
118
|
+
mirror remove
|
|
162
119
|
```
|
|
163
120
|
|
|
164
|
-
###
|
|
121
|
+
### 7. 断开连接
|
|
165
122
|
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
server_name mirror.example.com;
|
|
123
|
+
```bash
|
|
124
|
+
mirror stop
|
|
125
|
+
```
|
|
170
126
|
|
|
171
|
-
|
|
172
|
-
ssl_certificate /path/to/cert.pem;
|
|
173
|
-
ssl_certificate_key /path/to/key.pem;
|
|
127
|
+
## 命令参考
|
|
174
128
|
|
|
175
|
-
|
|
176
|
-
ssl_protocols TLSv1.2 TLSv1.3;
|
|
177
|
-
ssl_ciphers HIGH:!aNULL:!MD5;
|
|
178
|
-
ssl_prefer_server_ciphers on;
|
|
129
|
+
### `mirror link <server> [options]`
|
|
179
130
|
|
|
180
|
-
|
|
181
|
-
proxy_pass http://127.0.0.1:7331;
|
|
182
|
-
proxy_http_version 1.1;
|
|
131
|
+
连接到 Mirror 服务端。
|
|
183
132
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
proxy_set_header Connection "upgrade";
|
|
133
|
+
- `server`: 服务端地址(如 `mirror.tri-bank.online`)
|
|
134
|
+
- `-t, --token`: 认证令牌
|
|
187
135
|
|
|
188
|
-
|
|
189
|
-
proxy_set_header Host $host;
|
|
190
|
-
proxy_set_header X-Real-IP $remote_addr;
|
|
191
|
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
192
|
-
proxy_set_header X-Forwarded-Proto $scheme;
|
|
136
|
+
### `mirror add <domain/path> <target>`
|
|
193
137
|
|
|
194
|
-
|
|
195
|
-
proxy_connect_timeout 7d;
|
|
196
|
-
proxy_send_timeout 7d;
|
|
197
|
-
proxy_read_timeout 7d;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
138
|
+
添加代理规则。
|
|
200
139
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
listen 80;
|
|
204
|
-
server_name mirror.example.com;
|
|
205
|
-
return 301 https://$server_name$request_uri;
|
|
206
|
-
}
|
|
207
|
-
```
|
|
140
|
+
- `domain/path`: 域名和路径组合(如 `example.com/api`)
|
|
141
|
+
- `target`: 目标服务地址(如 `localhost:3001`)
|
|
208
142
|
|
|
209
|
-
|
|
143
|
+
**规则格式说明:**
|
|
144
|
+
- 域名和路径写在一起,使用 `/` 分隔
|
|
145
|
+
- 路径可以省略,省略时默认为 `/`
|
|
146
|
+
- 示例:
|
|
147
|
+
- `example.com/api` - 匹配 `example.com/api` 开头的请求
|
|
148
|
+
- `example.com` 或 `example.com/` - 匹配 `example.com` 域名的所有请求
|
|
210
149
|
|
|
211
|
-
|
|
212
|
-
2. **超时设置**:WebSocket 连接可能需要长时间保持,建议设置较长的超时时间(如 7 天)
|
|
213
|
-
3. **端口映射**:将 `127.0.0.1:7331` 替换为实际的 mirror host 服务地址和端口
|
|
214
|
-
4. **SSL 证书**:使用 HTTPS 时,需要配置有效的 SSL 证书
|
|
150
|
+
### `mirror remove [ruleId]`
|
|
215
151
|
|
|
216
|
-
|
|
152
|
+
删除代理规则。
|
|
217
153
|
|
|
218
|
-
|
|
219
|
-
# HTTPS (推荐)
|
|
220
|
-
mirror link wss://mirror.example.com?token=KJ82mZpX...
|
|
154
|
+
- `ruleId`: 规则 ID(可选,不指定则删除所有规则)
|
|
221
155
|
|
|
222
|
-
|
|
223
|
-
mirror link ws://mirror.example.com?token=KJ82mZpX...
|
|
224
|
-
```
|
|
156
|
+
### `mirror list`
|
|
225
157
|
|
|
226
|
-
|
|
158
|
+
查看所有代理规则。
|
|
227
159
|
|
|
228
|
-
###
|
|
160
|
+
### `mirror status`
|
|
229
161
|
|
|
230
|
-
|
|
162
|
+
查看当前连接状态和配置。
|
|
231
163
|
|
|
232
|
-
|
|
164
|
+
### `mirror stop`
|
|
233
165
|
|
|
234
|
-
|
|
235
|
-
# 在服务器上检查
|
|
236
|
-
ps aux | grep mirror
|
|
237
|
-
netstat -tlnp | grep 7331
|
|
238
|
-
```
|
|
166
|
+
断开与服务端的连接。
|
|
239
167
|
|
|
240
|
-
|
|
168
|
+
### `mirror server [options]`
|
|
241
169
|
|
|
242
|
-
|
|
243
|
-
proxy_pass http://127.0.0.1:7331; # 确保端口和地址正确
|
|
244
|
-
```
|
|
170
|
+
启动 HTTP 隧道服务端。
|
|
245
171
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
172
|
+
- `-p, --port`: HTTP 服务端口(默认 80)
|
|
173
|
+
- `-t, --tunnel-port`: WebSocket 隧道端口(默认 7332)
|
|
174
|
+
- `--host`: 监听地址(默认 0.0.0.0)
|
|
175
|
+
- `--token`: 认证令牌(可选)
|
|
176
|
+
- `--timeout`: 请求超时时间(毫秒,默认 30000)
|
|
250
177
|
|
|
251
|
-
|
|
178
|
+
## 规则匹配逻辑
|
|
252
179
|
|
|
253
|
-
|
|
180
|
+
1. 规则按路径长度降序排序(路径越长优先级越高)
|
|
181
|
+
2. 同长度的规则,后添加的优先级更高
|
|
182
|
+
3. 路径规则:请求路径以规则路径开头即匹配
|
|
183
|
+
4. 根路径规则(`/`):匹配该域名的所有路径
|
|
254
184
|
|
|
255
|
-
|
|
256
|
-
- 如果域名只配置了 HTTP,使用 `ws://` 协议
|
|
257
|
-
- 使用 IP 地址连接时,根据实际情况选择协议
|
|
185
|
+
### 示例
|
|
258
186
|
|
|
259
|
-
|
|
187
|
+
假设有以下规则:
|
|
260
188
|
|
|
261
|
-
```bash
|
|
262
|
-
# HTTPS 域名(推荐)
|
|
263
|
-
mirror link wss://mirror.example.com?token=xxx
|
|
264
|
-
|
|
265
|
-
# HTTP 域名(不推荐)
|
|
266
|
-
mirror link ws://mirror.example.com?token=xxx
|
|
267
189
|
```
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
### 🎯 实时文件同步(v0.1.0)
|
|
272
|
-
|
|
273
|
-
文件变更实时同步到远程,无论是否有命令在执行:
|
|
274
|
-
|
|
275
|
-
```bash
|
|
276
|
-
> npm run start
|
|
277
|
-
Server listening on port 3000
|
|
278
|
-
[同步] 同步中: src/index.ts (update) ← 实时同步,不干扰命令输出
|
|
279
|
-
[同步] ✓ 已同步: src/index.ts ← 2秒后自动清除
|
|
190
|
+
[1] example.com/api -> localhost:3001 (路径长度: 4)
|
|
191
|
+
[2] example.com/ -> localhost:5173 (路径长度: 1)
|
|
192
|
+
[3] example.com/api/users -> localhost:3002 (路径长度: 10)
|
|
280
193
|
```
|
|
281
194
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
195
|
+
请求匹配结果(按优先级排序):
|
|
196
|
+
1. `example.com/api/users/v1` → `localhost:3002`(匹配规则 3,路径长度 10)
|
|
197
|
+
2. `example.com/api/products` → `localhost:3001`(匹配规则 1,路径长度 4)
|
|
198
|
+
3. `example.com/` → `localhost:5173`(匹配规则 2,路径长度 1)
|
|
199
|
+
4. `example.com/about` → `localhost:5173`(匹配规则 2,路径长度 1)
|
|
200
|
+
|
|
201
|
+
## 配置文件
|
|
202
|
+
|
|
203
|
+
规则存储在 `~/.mirror/rules.json` 中:
|
|
204
|
+
|
|
205
|
+
```json
|
|
206
|
+
{
|
|
207
|
+
"server": "mirror.tri-bank.online",
|
|
208
|
+
"token": "your-token",
|
|
209
|
+
"rules": [
|
|
210
|
+
{
|
|
211
|
+
"id": 1,
|
|
212
|
+
"domain": "example.com",
|
|
213
|
+
"path": "/api",
|
|
214
|
+
"target": "localhost:3001",
|
|
215
|
+
"priority": "high",
|
|
216
|
+
"createdAt": "2026-02-18T03:50:18.627Z"
|
|
217
|
+
}
|
|
218
|
+
]
|
|
219
|
+
}
|
|
302
220
|
```
|
|
303
221
|
|
|
304
|
-
|
|
222
|
+
断开连接后规则会保留,下次连接时自动同步。
|
|
305
223
|
|
|
306
|
-
|
|
307
|
-
- 状态信息会在 1 秒后自动清除
|
|
308
|
-
- 命令输出正常显示,与状态信息互不干扰
|
|
224
|
+
## 进程管理
|
|
309
225
|
|
|
310
|
-
|
|
226
|
+
Mirror 客户端使用锁文件机制确保同一时间只有一个实例在运行。锁文件位于 `~/.mirror/.lock`。
|
|
311
227
|
|
|
312
|
-
-
|
|
313
|
-
-
|
|
228
|
+
- 如果尝试启动第二个实例,会提示已有进程在运行
|
|
229
|
+
- 如果进程异常退出,锁文件会被自动清理
|
|
230
|
+
- 使用 `mirror stop` 命令可以安全停止运行中的客户端
|
|
314
231
|
|
|
315
232
|
## 注意事项
|
|
316
233
|
|
|
317
|
-
-
|
|
318
|
-
-
|
|
319
|
-
-
|
|
320
|
-
-
|
|
321
|
-
- ⚠️ 使用域名连接时,确保使用正确的协议(HTTPS 使用 wss://,HTTP 使用 ws://)
|
|
322
|
-
- ⚠️ 使用反向代理时,确保 Nginx 配置了正确的 WebSocket 升级头
|
|
323
|
-
- ℹ️ 新特性需要客户端和服务端版本匹配才能使用
|
|
324
|
-
|
|
325
|
-
## 开发
|
|
326
|
-
|
|
327
|
-
```bash
|
|
328
|
-
# 安装依赖
|
|
329
|
-
npm install
|
|
330
|
-
|
|
331
|
-
# 构建
|
|
332
|
-
npm run build
|
|
333
|
-
|
|
334
|
-
# 测试
|
|
335
|
-
npm test
|
|
336
|
-
|
|
337
|
-
# Lint
|
|
338
|
-
npm run lint
|
|
339
|
-
```
|
|
234
|
+
- 服务端和客户端必须使用相同的 token(如果配置了)
|
|
235
|
+
- 端口需要开放防火墙访问
|
|
236
|
+
- 建议在生产环境使用 HTTPS
|
|
237
|
+
- WebSocket 隧道使用 wss:// 协议,需要 SSL 证书
|
|
340
238
|
|
|
341
|
-
##
|
|
239
|
+
## 许可证
|
|
342
240
|
|
|
343
241
|
MIT
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mirror CLI 命令实现
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* link 命令:连接服务端
|
|
6
|
+
*/
|
|
7
|
+
export declare function linkCommand(server: string, options: {
|
|
8
|
+
token?: string;
|
|
9
|
+
}): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* add 命令:添加代理规则
|
|
12
|
+
*/
|
|
13
|
+
export declare function addCommand(domainPath: string, target: string): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* remove 命令:删除代理规则
|
|
16
|
+
*/
|
|
17
|
+
export declare function removeCommand(ruleId?: string): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* list 命令:查看代理规则
|
|
20
|
+
*/
|
|
21
|
+
export declare function listCommand(): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* stop 命令:断开连接
|
|
24
|
+
*/
|
|
25
|
+
export declare function stopCommand(): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* status 命令:查看连接状态
|
|
28
|
+
*/
|
|
29
|
+
export declare function statusCommand(): Promise<void>;
|
|
30
|
+
//# sourceMappingURL=cli-commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-commands.d.ts","sourceRoot":"","sources":["../../src/cli/cli-commands.ts"],"names":[],"mappings":"AAAA;;GAEG;AAmEH;;GAEG;AACH,wBAAsB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA8F5F;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA0DlF;AAED;;GAEG;AACH,wBAAsB,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAoClE;AAED;;GAEG;AACH,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAsBjD;AAED;;GAEG;AACH,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CA+BjD;AAED;;GAEG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAyDnD"}
|