xrunx commited on
Commit
ef590e4
·
verified ·
1 Parent(s): f5a1194

Upload 6 files

Browse files
Files changed (7) hide show
  1. .gitattributes +1 -0
  2. Dockerfile +13 -0
  3. README +13 -0
  4. index.js +512 -0
  5. package.json +20 -0
  6. server +3 -0
  7. start.sh +28 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ server filter=lfs diff=lfs merge=lfs -text
Dockerfile ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM node:slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY . .
6
+
7
+ EXPOSE 7860
8
+
9
+ RUN apt-get update && \
10
+ chmod 775 server index.js package.json start.sh /app &&\
11
+ npm install
12
+
13
+ CMD ["node", "index.js"]
README ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ title: Vless Proxy Service
2
+ emoji: 🚀
3
+ colorFrom: blue
4
+ colorTo: purple
5
+ sdk: docker
6
+ app_port: 7860
7
+ pinned: false
8
+ short_description: A Vless proxy service with Nezha monitoring support
9
+ tags:
10
+ - proxy
11
+ - vless
12
+ - networking
13
+ - monitoring
index.js ADDED
@@ -0,0 +1,512 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const os = require('os');
2
+ const http = require('http');
3
+ const net = require('net');
4
+ const { exec, execSync } = require('child_process');
5
+
6
+ function ensureModule(name) {
7
+ try {
8
+ require.resolve(name);
9
+ } catch (e) {
10
+ console.log(`Module '${name}' not found. Installing...`);
11
+ execSync(`npm install ${name}`, { stdio: 'inherit' });
12
+ }
13
+ }
14
+
15
+ ensureModule('axios');
16
+ ensureModule('ws');
17
+
18
+ const axios = require('axios');
19
+ const { WebSocketServer, createWebSocketStream } = require('ws');
20
+
21
+ // 环境变量配置 - 适配Huggingface部署
22
+ const NEZHA_SERVER = process.env.NEZHA_SERVER || '';
23
+ const NEZHA_PORT = process.env.NEZHA_PORT || '';
24
+ const NEZHA_KEY = process.env.NEZHA_KEY || '';
25
+ const NAME = process.env.NAME || os.hostname();
26
+
27
+ // Vless配置
28
+ const UUID = process.env.UUID || 'e6542600-b09f-4dac-be5d-1c32fca89901';
29
+ const DOMAIN = process.env.DOMAIN || 'huggingface.chinax.site'; // 用户需要设置的域名
30
+
31
+ // 性能配置
32
+ const LOG_FLAG = process.env.LOG_FLAG === 'true' || false; // 默认关闭详细日志
33
+ const MAX_CONNECTIONS = parseInt(process.env.MAX_CONNECTIONS) || 100000; // 最大并发连接数
34
+ const SOCKET_TIMEOUT = parseInt(process.env.SOCKET_TIMEOUT) || 100000; // 连接超时时间
35
+
36
+ // Huggingface固定端口7860
37
+ const port = 7860;
38
+ const uuid = UUID;
39
+ const uuidNoHyphens = uuid.replace(/-/g, '');
40
+
41
+ console.log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
42
+ console.log("一键无交互Vless代理脚本 - Huggingface版");
43
+ console.log("当前版本:1.0.0 Huggingface适配版");
44
+ console.log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
45
+
46
+ let apiData = [];
47
+ let lastUpdateTime = new Date().toLocaleString();
48
+
49
+ // 统计信息
50
+ let connectionStats = {
51
+ totalConnections: 0,
52
+ activeConnections: 0,
53
+ totalDataTransferred: 0,
54
+ startTime: new Date()
55
+ };
56
+
57
+ // 内置节点列表 - 来自原始app.js
58
+ const builtinNodes = [
59
+ // Cloudflare IP地址
60
+ { domain: "104.16.0.0", name: `Vl-ws-tls-${NAME}` },
61
+ { domain: "104.17.0.0", name: `Vl-ws-tls-${NAME}` },
62
+ { domain: "104.18.0.0", name: `Vl-ws-tls-${NAME}` },
63
+ { domain: "104.19.0.0", name: `Vl-ws-tls-${NAME}` },
64
+ { domain: "104.20.0.0", name: `Vl-ws-tls-${NAME}` },
65
+ { domain: "104.21.0.0", name: `Vl-ws-tls-${NAME}` },
66
+ { domain: "104.22.0.0", name: `Vl-ws-tls-${NAME}` },
67
+ { domain: "104.24.0.0", name: `Vl-ws-tls-${NAME}` },
68
+ { domain: "104.25.0.0", name: `Vl-ws-tls-${NAME}` },
69
+ { domain: "104.26.0.0", name: `Vl-ws-tls-${NAME}` },
70
+ { domain: "104.27.0.0", name: `Vl-ws-tls-${NAME}` },
71
+ // 官方优选
72
+ { domain: "cf.090227.xyz", name: "三网自适应分流官方优选" },
73
+ { domain: "ct.090227.xyz", name: "电信官方优选" },
74
+ { domain: "cmcc.090227.xyz", name: "移动官方优选" },
75
+ // 官方域名优选
76
+ { domain: "shopify.com", name: "优选官方域名-shopify" },
77
+ { domain: "time.is", name: "优选官方域名-time" },
78
+ { domain: "icook.hk", name: "优选官方域名-icook.hk" },
79
+ { domain: "icook.tw", name: "优选官方域名-icook.tw" },
80
+ { domain: "ip.sb", name: "优选官方域名-ip.sb" },
81
+ { domain: "japan.com", name: "优选官方域名-japan" },
82
+ { domain: "malaysia.com", name: "优选官方域名-malaysia" },
83
+ { domain: "russia.com", name: "优选官方域名-russia" },
84
+ { domain: "singapore.com", name: "优选官方域名-singapore" },
85
+ { domain: "skk.moe", name: "优选官方域名-skk" },
86
+ { domain: "www.visa.com.sg", name: "优选官方域名-visa.sg" },
87
+ { domain: "www.visa.com.hk", name: "优选官方域名-visa.hk" },
88
+ { domain: "www.visa.com.tw", name: "优选官方域名-visa.tw" },
89
+ { domain: "www.visa.co.jp", name: "优选官方域名-visa.jp" },
90
+ { domain: "www.visakorea.com", name: "优选官方域名-visa.kr" },
91
+ { domain: "www.gco.gov.qa", name: "优选官方域名-gov.qa" },
92
+ { domain: "www.gov.se", name: "优选官方域名-gov.se" },
93
+ { domain: "www.gov.ua", name: "优选官方域名-gov.ua" },
94
+ // 第三方维护
95
+ { domain: "cfip.xxxxxxxx.tk", name: "OTC提供维护官方优选" },
96
+ { domain: "bestcf.onecf.eu.org", name: "Mingyu提供维护官方优选" },
97
+ { domain: "cf.zhetengsha.eu.org", name: "小一提供维护官方优选" },
98
+ { domain: "xn--b6gac.eu.org", name: "第三方维护官方优选" },
99
+ { domain: "yx.887141.xyz", name: "第三方维护官方优选" },
100
+ { domain: "8.889288.xyz", name: "第三方维护官方优选" },
101
+ { domain: "cfip.1323123.xyz", name: "第三方维护官方优选" },
102
+ { domain: "cf.515188.xyz", name: "第三方维护官方优选" },
103
+ { domain: "cf-st.annoy.eu.org", name: "第三方维护官方优选" },
104
+ { domain: "cf.0sm.com", name: "第三方维护官方优选" },
105
+ { domain: "cf.877771.xyz", name: "第三方维护官方优选" },
106
+ { domain: "cf.345673.xyz", name: "第三方维护官方优选" },
107
+ { domain: "bestproxy.onecf.eu.org", name: "Mingyu提供维护反代优选" },
108
+ { domain: "proxy.xxxxxxxx.tk", name: "OTC提供维护反代优选" }
109
+ ];
110
+
111
+ // API配置
112
+ const apiList = [
113
+ {
114
+ url: 'https://ipdb.api.030101.xyz/?type=bestcf&country=true',
115
+ namePrefix: '优选官方API(1-'
116
+ },
117
+ {
118
+ url: 'https://addressesapi.090227.xyz/CloudFlareYes',
119
+ namePrefix: '优选官方API(2-'
120
+ },
121
+ {
122
+ url: 'https://addressesapi.090227.xyz/ip.164746.xyz',
123
+ namePrefix: '优选官方API(3-'
124
+ },
125
+ {
126
+ url: 'https://ipdb.api.030101.xyz/?type=bestproxy&country=true',
127
+ namePrefix: '优选反代API(1-'
128
+ }
129
+ ];
130
+
131
+ // 获取API数据
132
+ async function fetchApiData() {
133
+ let allResults = [];
134
+
135
+ try {
136
+ for (let apiIndex = 0; apiIndex < apiList.length; apiIndex++) {
137
+ const api = apiList[apiIndex];
138
+ console.log(`正在请求 API: ${api.url}`);
139
+
140
+ try {
141
+ const response = await axios.get(api.url, { timeout: 10000 });
142
+ const data = response.data;
143
+
144
+ if (Array.isArray(data)) {
145
+ const results = data.map((item, index) => ({
146
+ domain: item.ip || item,
147
+ name: `${api.namePrefix}${index + 1})`
148
+ }));
149
+ allResults = allResults.concat(results);
150
+ } else if (typeof data === 'string') {
151
+ const lines = data.split('\n').filter(line => line.trim());
152
+ const results = lines.map((line, index) => ({
153
+ domain: line.trim(),
154
+ name: `${api.namePrefix}${index + 1})`
155
+ }));
156
+ allResults = allResults.concat(results);
157
+ }
158
+ } catch (error) {
159
+ console.error(`API ${api.url} 请求失败:`, error.message);
160
+ }
161
+ }
162
+
163
+ console.log(`成功获取 ${allResults.length} 个IP地址`);
164
+ return allResults;
165
+ } catch (error) {
166
+ console.error('获取API数据时出错:', error);
167
+ return [];
168
+ }
169
+ }
170
+
171
+ // 生成Vless配置 - 按照指定格式
172
+ function generateVlessConfig(item) {
173
+ // 确保域名格式正确
174
+ const cleanDomain = item.domain.replace(/#.*$/, ''); // 移除可能的注释部分
175
+
176
+ // 不进行URL编码,直接使用原始中文名称
177
+ const nodeName = item.name;
178
+
179
+ // 按照指定格式构造:vless://${UUID}@${item.domain}:443?encryption=none&security=tls&sni=${DOMAIN}&fp=chrome&type=ws&host=${DOMAIN}&path=%2F#${item.name}
180
+ const vlessUrl = `vless://${UUID}@${cleanDomain}:443?encryption=none&security=tls&sni=${DOMAIN}&fp=chrome&type=ws&host=${DOMAIN}&path=%2F#${nodeName}`;
181
+ return vlessUrl;
182
+ }
183
+
184
+ // WebSocket处理 - 使用app.js的高效流管道方式
185
+ function handleWebSocket(ws, request) {
186
+ const clientIP = request.headers['x-forwarded-for'] || request.headers['x-real-ip'] || request.connection.remoteAddress;
187
+ const userAgent = request.headers['user-agent'] || 'Unknown';
188
+
189
+ if (LOG_FLAG) {
190
+ console.log('🔗 WebSocket连接建立:');
191
+ console.log(` 客户端IP: ${clientIP}`);
192
+ console.log(` User-Agent: ${userAgent}`);
193
+ }
194
+
195
+ // 更新连接统计
196
+ connectionStats.totalConnections++;
197
+ connectionStats.activeConnections++;
198
+
199
+ // 使用once监听第一条消息(Vless握手)
200
+ ws.once('message', msg => {
201
+ try {
202
+ if (LOG_FLAG) {
203
+ console.log(`📨 收到Vless握手消息 [${clientIP}]:`, {
204
+ 长度: msg.length,
205
+ 前16字节: msg.slice(0, Math.min(16, msg.length)).toString('hex')
206
+ });
207
+ }
208
+
209
+ // 解析Vless协议 - 参考app.js的方式
210
+ const [VERSION] = msg;
211
+ const id = msg.slice(1, 17);
212
+ const receivedUuid = id.toString('hex');
213
+
214
+ if (LOG_FLAG) {
215
+ console.log(`🔍 Vless协议解析 [${clientIP}]:`, {
216
+ 版本: VERSION,
217
+ UUID: receivedUuid,
218
+ 是否匹配: receivedUuid === uuidNoHyphens
219
+ });
220
+ }
221
+
222
+ // 验证UUID - 使用app.js的验证方式
223
+ if (!id.every((v, i) => v == parseInt(uuidNoHyphens.substr(i * 2, 2), 16))) {
224
+ if (LOG_FLAG) {
225
+ console.log(`❌ UUID验证失败 [${clientIP}]: 期望 ${uuidNoHyphens}, 收到 ${receivedUuid}`);
226
+ }
227
+ ws.close(1000, 'Invalid UUID');
228
+ return;
229
+ }
230
+
231
+ if (LOG_FLAG) {
232
+ console.log(`✅ UUID验证成功 [${clientIP}]`);
233
+ }
234
+
235
+ // 解析目标地址 - 使用app.js的解析方式
236
+ let i = msg.slice(17, 18).readUInt8() + 19;
237
+ const port = msg.slice(i, i += 2).readUInt16BE(0);
238
+ const ATYP = msg.slice(i, i += 1).readUInt8();
239
+
240
+ let host = '';
241
+ if (ATYP == 1) { // IPv4
242
+ host = msg.slice(i, i += 4).join('.');
243
+ } else if (ATYP == 2) { // 域名
244
+ host = new TextDecoder().decode(msg.slice(i + 1, i += 1 + msg.slice(i, i + 1).readUInt8()));
245
+ } else if (ATYP == 3) { // IPv6
246
+ host = msg.slice(i, i += 16).reduce((s, b, i, a) => (i % 2 ? s.concat(a.slice(i - 1, i + 1)) : s), [])
247
+ .map(b => b.readUInt16BE(0).toString(16)).join(':');
248
+ }
249
+
250
+ if (LOG_FLAG) {
251
+ console.log(`🎯 目标地址 [${clientIP}]: ${host}:${port}`);
252
+ }
253
+
254
+ // 发送Vless响应 - 使用app.js的方式
255
+ ws.send(new Uint8Array([VERSION, 0]));
256
+ if (LOG_FLAG) {
257
+ console.log(`📤 发送Vless握手响应 [${clientIP}]`);
258
+ }
259
+
260
+ // 创建WebSocket流 - 使用app.js的高效方式
261
+ const duplex = createWebSocketStream(ws);
262
+
263
+ // 建立TCP连接并使用流管道 - 完全按照app.js的方式
264
+ const tcpSocket = net.connect({ host, port }, function () {
265
+ if (LOG_FLAG) {
266
+ console.log(`🔗 已连接到目标服务器 [${clientIP}]: ${host}:${port}`);
267
+ }
268
+
269
+ // 转发握手消息中的剩余数据
270
+ if (i < msg.length) {
271
+ const extraData = msg.slice(i);
272
+ this.write(extraData);
273
+ connectionStats.totalDataTransferred += extraData.length;
274
+ if (LOG_FLAG) {
275
+ console.log(`📤 转发额外数据到目标服务器 [${clientIP}]: ${extraData.length} 字节`);
276
+ }
277
+ }
278
+
279
+ // 建立双向流管道 - 完全按照app.js的方式,移除日志以提高性能
280
+ duplex.on('error', () => {}).pipe(this).on('error', () => {}).pipe(duplex);
281
+
282
+ }).on('error', (error) => {
283
+ if (LOG_FLAG) {
284
+ console.error(`❌ TCP连接错误 [${clientIP}]: ${error.message}`);
285
+ }
286
+ if (ws.readyState === 1) {
287
+ ws.close();
288
+ }
289
+ }).on('close', () => {
290
+ if (LOG_FLAG) {
291
+ console.log(`🔌 TCP连接关闭 [${clientIP}]`);
292
+ }
293
+ if (ws.readyState === 1) {
294
+ ws.close();
295
+ }
296
+ });
297
+
298
+ // 设置连接超时 - 使用配置的超时时间
299
+ tcpSocket.setTimeout(SOCKET_TIMEOUT, () => {
300
+ if (LOG_FLAG) {
301
+ console.error(`⏰ TCP连接超时 [${clientIP}]: ${host}:${port}`);
302
+ }
303
+ tcpSocket.destroy();
304
+ if (ws.readyState === 1) {
305
+ ws.close();
306
+ }
307
+ });
308
+
309
+ } catch (error) {
310
+ if (LOG_FLAG) {
311
+ console.error(`❌ Vless握手处理错误 [${clientIP}]:`, error);
312
+ }
313
+ ws.close();
314
+ }
315
+ }).on('error', (error) => {
316
+ if (LOG_FLAG) {
317
+ console.error(`❌ WebSocket错误 [${clientIP}]:`, error);
318
+ }
319
+ connectionStats.activeConnections--;
320
+ }).on('close', (code, reason) => {
321
+ if (LOG_FLAG) {
322
+ console.log(`🔌 WebSocket连接关闭 [${clientIP}]:`, {
323
+ 代码: code,
324
+ 原因: reason?.toString() || '无'
325
+ });
326
+ }
327
+ connectionStats.activeConnections--;
328
+ });
329
+ }
330
+
331
+ // 启动Nezha监控
332
+ function startNezhaMonitoring() {
333
+ if (NEZHA_SERVER && NEZHA_PORT && NEZHA_KEY) {
334
+ let NEZHA_TLS = (NEZHA_PORT === '443') ? '--tls' : '';
335
+ const command = `./server -s ${NEZHA_SERVER}:${NEZHA_PORT} -p ${NEZHA_KEY} ${NEZHA_TLS} --skip-conn --disable-auto-update --skip-procs --report-delay 4 >/dev/null 2>&1 &`;
336
+ try {
337
+ exec(command);
338
+ console.log('Nezha监控已启动');
339
+ } catch (error) {
340
+ console.error(`Nezha监控启动错误: ${error}`);
341
+ }
342
+ } else {
343
+ console.log('未配置Nezha监控,跳过启动');
344
+ }
345
+ }
346
+
347
+ // 主函数
348
+ async function main() {
349
+ console.log('正在获取API数据...');
350
+ apiData = await fetchApiData();
351
+ lastUpdateTime = new Date().toLocaleString();
352
+
353
+ // 启动Nezha监控
354
+ startNezhaMonitoring();
355
+
356
+ // 创建WebSocket服务器
357
+ const wss = new WebSocketServer({ noServer: true });
358
+
359
+ // 创建HTTP服务器
360
+ const server = http.createServer((req, res) => {
361
+ const url = new URL(req.url, `http://${req.headers.host}`);
362
+ const path = url.pathname;
363
+ const clientIP = req.headers['x-forwarded-for'] || req.headers['x-real-ip'] || req.connection.remoteAddress;
364
+
365
+ // 检查Base64参数
366
+ const isBase64 = url.searchParams.has('base64') || url.searchParams.has('b64');
367
+
368
+ // 详细的请求日志
369
+ console.log(`\n🌐 收到HTTP请求:`);
370
+ console.log(` 时间: ${new Date().toLocaleString()}`);
371
+ console.log(` 客户端IP: ${clientIP}`);
372
+ console.log(` 方法: ${req.method}`);
373
+ console.log(` URL: ${req.url}`);
374
+ console.log(` 路径: ${path}`);
375
+ console.log(` Host: ${req.headers.host}`);
376
+ console.log(` User-Agent: ${req.headers['user-agent'] || 'Unknown'}`);
377
+ console.log(` Base64请求: ${isBase64}`);
378
+ console.log(` 所有请求头:`, JSON.stringify(req.headers, null, 2));
379
+
380
+ // 设置响应头,确保UTF-8编码
381
+ const headers = {
382
+ 'Content-Type': 'text/plain; charset=utf-8',
383
+ 'Access-Control-Allow-Origin': '*',
384
+ 'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
385
+ 'Access-Control-Allow-Headers': 'Content-Type'
386
+ };
387
+
388
+ if (path === '/') {
389
+ const totalNodes = builtinNodes.length + apiData.length + (DOMAIN && DOMAIN !== 'your-domain.com' ? 1 : 0);
390
+ const uptime = Math.floor((new Date() - connectionStats.startTime) / 1000);
391
+ const statsInfo = `Hello, World-YGkkk
392
+ 内置节点数量: ${builtinNodes.length}
393
+ API获取节点数量: ${apiData.length}
394
+ 总节点数量: ${totalNodes}
395
+ 最后更新时间: ${lastUpdateTime}
396
+ UUID: ${uuid}
397
+ DOMAIN: ${DOMAIN}
398
+
399
+ === 连接统计 ===
400
+ 总连接数: ${connectionStats.totalConnections}
401
+ 当前活跃连接: ${connectionStats.activeConnections}
402
+ 总数据传输: ${(connectionStats.totalDataTransferred / 1024 / 1024).toFixed(2)} MB
403
+ 运行时间: ${uptime} 秒`;
404
+
405
+ if (LOG_FLAG) {
406
+ console.log(`📤 返回根路径响应 [${clientIP}]:`);
407
+ console.log(` 响应长度: ${statsInfo.length}`);
408
+ console.log(` 总节点数: ${totalNodes}`);
409
+ console.log(` 活跃连接: ${connectionStats.activeConnections}`);
410
+ }
411
+
412
+ res.writeHead(200, headers);
413
+ res.end(statsInfo);
414
+ } else if (path === `/${uuid}` || path === `/${uuidNoHyphens}`) {
415
+ // 生成Vless配置列表
416
+ let vlessConfigs = [];
417
+
418
+ // 首先添加基本域名节点(直连)
419
+ if (DOMAIN && DOMAIN !== 'your-domain.com') {
420
+ const domainNode = { domain: DOMAIN, name: `直连-${NAME}` };
421
+ vlessConfigs.push(generateVlessConfig(domainNode));
422
+ }
423
+
424
+ // 添加内置节点
425
+ builtinNodes.forEach(item => {
426
+ const config = generateVlessConfig(item);
427
+ vlessConfigs.push(config);
428
+ });
429
+
430
+ // 添加API获取的节点
431
+ apiData.forEach(item => {
432
+ const config = generateVlessConfig(item);
433
+ vlessConfigs.push(config);
434
+ });
435
+
436
+ let result = vlessConfigs.join('\n');
437
+
438
+ if (LOG_FLAG) {
439
+ console.log(`📤 返回配置页面响应 [${clientIP}]:`);
440
+ console.log(` 配置数量: ${vlessConfigs.length}`);
441
+ console.log(` Base64编码: ${isBase64}`);
442
+ console.log(` 原始长度: ${result.length}`);
443
+ }
444
+
445
+ if (isBase64) {
446
+ // 确保Base64编码正确处理UTF-8
447
+ result = Buffer.from(result, 'utf8').toString('base64');
448
+ if (LOG_FLAG) {
449
+ console.log(` Base64长度: ${result.length}`);
450
+ }
451
+ } else {
452
+ result += '\n';
453
+ }
454
+
455
+ res.writeHead(200, headers);
456
+ res.end(result);
457
+ } else {
458
+ res.writeHead(404, headers);
459
+ res.end('Not Found\n');
460
+ }
461
+ });
462
+
463
+ // WebSocket升级处理
464
+ server.on('upgrade', (request, socket, head) => {
465
+ try {
466
+ if (LOG_FLAG) {
467
+ console.log(`🔄 WebSocket升级请求: ${request.url}`);
468
+ }
469
+
470
+ // 使用ws库的WebSocketServer来处理升级
471
+ wss.handleUpgrade(request, socket, head, (ws) => {
472
+ if (LOG_FLAG) {
473
+ console.log('✅ WebSocket连接已建立');
474
+ }
475
+ handleWebSocket(ws, request);
476
+ });
477
+ } catch (error) {
478
+ if (LOG_FLAG) {
479
+ console.error('❌ WebSocket升级错误:', error);
480
+ }
481
+ socket.end();
482
+ }
483
+ });
484
+
485
+ // 优化服务器性能
486
+ server.maxConnections = MAX_CONNECTIONS;
487
+ server.timeout = SOCKET_TIMEOUT;
488
+ server.keepAliveTimeout = 5000;
489
+ server.headersTimeout = 10000;
490
+
491
+ // 启动服务器
492
+ server.listen(port, () => {
493
+ console.log(`✅ HTTP服务器已启动,端口: ${port}`);
494
+ console.log(`📍 本地访问地址: http://localhost:${port}/`);
495
+ console.log(`📍 配置页面: http://localhost:${port}/${uuid}`);
496
+ console.log(`🔧 UUID: ${uuid}`);
497
+ console.log(`⚙️ 性能配置:`);
498
+ console.log(` 最大连接数: ${MAX_CONNECTIONS}`);
499
+ console.log(` 连接超时: ${SOCKET_TIMEOUT}ms`);
500
+ console.log(` 详细日志: ${LOG_FLAG ? '开启' : '关闭'}`);
501
+ });
502
+
503
+ // 定时更新API数据
504
+ setInterval(async () => {
505
+ console.log('定时更新API数据...');
506
+ apiData = await fetchApiData();
507
+ lastUpdateTime = new Date().toLocaleString();
508
+ }, 300000); // 5分钟更新一次
509
+ }
510
+
511
+ // 启动应用
512
+ main().catch(console.error);
package.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "vless-nodejs-huggingface",
3
+ "version": "1.0.0",
4
+ "description": "Vless Node.js proxy for Huggingface deployment",
5
+ "main": "index.js",
6
+ "author": "yonggekkk",
7
+ "license": "MIT",
8
+ "private": false,
9
+ "scripts": {
10
+ "start": "node index.js",
11
+ "test": "echo \"Error: no test specified\" && exit 1"
12
+ },
13
+ "dependencies": {
14
+ "axios": "^1.6.2",
15
+ "ws": "^8.14.2"
16
+ },
17
+ "engines": {
18
+ "node": ">=14"
19
+ }
20
+ }
server ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4783411caceee4ff86eebca1f938e542535c9075eda654de52ce13528bf5d5a5
3
+ size 17194293
start.sh ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/bash
2
+
3
+ # Nezha监控配置 - 请根据实际情况修改
4
+ export NEZHA_SERVER="xxx.xxxx.com"
5
+ export NEZHA_PORT="5555" # 当端口设置为443时,自动开启TLS
6
+ export NEZHA_KEY="d0hJ9XrXSb1abcdefg"
7
+
8
+ # Vless配置 - 请根据实际情况修改
9
+ export UUID="e6542600-b09f-4dac-be5d-1c32fca89901"
10
+ export NAME="Huggingface-Vless"
11
+
12
+ # 启动Nezha监控客户端
13
+ chmod +x server
14
+ if [ "$NEZHA_PORT" = "443" ]; then
15
+ NEZHA_TLS="--tls"
16
+ else
17
+ NEZHA_TLS=""
18
+ fi
19
+
20
+ # 后台启动Nezha监控
21
+ nohup ./server -s ${NEZHA_SERVER}:${NEZHA_PORT} -p ${NEZHA_KEY} ${NEZHA_TLS} --skip-conn --disable-auto-update --skip-procs --report-delay 4 > /dev/null 2>&1 &
22
+
23
+ # 启动Node.js应用
24
+ echo "启动Vless代理服务..."
25
+ echo "UUID: $UUID"
26
+ echo "Nezha服务器: $NEZHA_SERVER:$NEZHA_PORT"
27
+
28
+ node index.js