Update index.js
Browse files
index.js
CHANGED
|
@@ -2,31 +2,27 @@ const http = require('http');
|
|
| 2 |
const fs = require('fs');
|
| 3 |
const path = require('path');
|
| 4 |
const { WebSocketServer } = require('ws');
|
|
|
|
| 5 |
|
| 6 |
-
// ===============
|
| 7 |
-
const UUID = 'b831381d-6324-4d53-ad4f-8cda48b30811';
|
| 8 |
-
const DOMAIN = 'wky-tty.hf.space';
|
| 9 |
-
const WSPATH = 'ws';
|
| 10 |
-
const SUB_PATH = 'sub';
|
| 11 |
const PORT = 7860;
|
| 12 |
-
// =====================================
|
| 13 |
|
| 14 |
const requestHandler = (req, res) => {
|
| 15 |
if (req.url === '/') {
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
res.end(err ? '<h1>Hugging Face Proxy</h1>' : content);
|
| 19 |
-
});
|
| 20 |
}
|
| 21 |
else if (req.url === `/${SUB_PATH}`) {
|
| 22 |
const config = `vless://${UUID}@${DOMAIN}?encryption=none&security=tls&sni=${DOMAIN}&fp=chrome&type=ws&host=${DOMAIN}&path=%2F${WSPATH}#HF-${DOMAIN}`;
|
| 23 |
const base64 = Buffer.from(config).toString('base64');
|
| 24 |
-
|
| 25 |
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
| 26 |
res.end(base64);
|
| 27 |
-
|
| 28 |
-
}
|
| 29 |
-
else {
|
| 30 |
res.writeHead(404);
|
| 31 |
res.end('Not Found');
|
| 32 |
}
|
|
@@ -36,35 +32,49 @@ const server = http.createServer(requestHandler);
|
|
| 36 |
const wss = new WebSocketServer({ server });
|
| 37 |
|
| 38 |
wss.on('connection', (ws, req) => {
|
| 39 |
-
console.log('New
|
|
|
|
|
|
|
| 40 |
|
| 41 |
ws.once('message', (data) => {
|
| 42 |
const buf = Buffer.from(data);
|
| 43 |
|
| 44 |
-
//
|
| 45 |
if (buf[0] === 0) {
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
}
|
| 55 |
});
|
| 56 |
|
| 57 |
-
ws.on('
|
| 58 |
-
|
| 59 |
-
|
|
|
|
| 60 |
});
|
| 61 |
|
| 62 |
ws.on('close', () => {
|
|
|
|
| 63 |
console.log('Connection closed');
|
| 64 |
});
|
|
|
|
|
|
|
| 65 |
});
|
| 66 |
|
| 67 |
server.listen(PORT, () => {
|
| 68 |
-
console.log(`✅
|
| 69 |
-
console.log(`訂閱
|
| 70 |
});
|
|
|
|
| 2 |
const fs = require('fs');
|
| 3 |
const path = require('path');
|
| 4 |
const { WebSocketServer } = require('ws');
|
| 5 |
+
const net = require('net');
|
| 6 |
|
| 7 |
+
// =============== 配置區 ===============
|
| 8 |
+
const UUID = 'b831381d-6324-4d53-ad4f-8cda48b30811';
|
| 9 |
+
const DOMAIN = 'wky-tty.hf.space';
|
| 10 |
+
const WSPATH = 'ws';
|
| 11 |
+
const SUB_PATH = 'sub';
|
| 12 |
const PORT = 7860;
|
| 13 |
+
// =====================================
|
| 14 |
|
| 15 |
const requestHandler = (req, res) => {
|
| 16 |
if (req.url === '/') {
|
| 17 |
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
| 18 |
+
res.end('<h1>Hugging Face VLESS Proxy</h1><p>Running...</p>');
|
|
|
|
|
|
|
| 19 |
}
|
| 20 |
else if (req.url === `/${SUB_PATH}`) {
|
| 21 |
const config = `vless://${UUID}@${DOMAIN}?encryption=none&security=tls&sni=${DOMAIN}&fp=chrome&type=ws&host=${DOMAIN}&path=%2F${WSPATH}#HF-${DOMAIN}`;
|
| 22 |
const base64 = Buffer.from(config).toString('base64');
|
|
|
|
| 23 |
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
| 24 |
res.end(base64);
|
| 25 |
+
} else {
|
|
|
|
|
|
|
| 26 |
res.writeHead(404);
|
| 27 |
res.end('Not Found');
|
| 28 |
}
|
|
|
|
| 32 |
const wss = new WebSocketServer({ server });
|
| 33 |
|
| 34 |
wss.on('connection', (ws, req) => {
|
| 35 |
+
console.log('New Connection from', req.socket.remoteAddress);
|
| 36 |
+
|
| 37 |
+
let targetSocket = null;
|
| 38 |
|
| 39 |
ws.once('message', (data) => {
|
| 40 |
const buf = Buffer.from(data);
|
| 41 |
|
| 42 |
+
// 簡單 VLESS 握手
|
| 43 |
if (buf[0] === 0) {
|
| 44 |
+
ws.send(Buffer.from([0x00, 0x00])); // 成功回應
|
| 45 |
+
console.log('✅ VLESS Handshake OK');
|
| 46 |
+
|
| 47 |
+
// 建立到真實目標的 TCP 連線(這裡是簡化版)
|
| 48 |
+
targetSocket = net.createConnection(443, '1.1.1.1'); // 測試用,可改成其他
|
| 49 |
+
|
| 50 |
+
targetSocket.on('connect', () => {
|
| 51 |
+
console.log('Target connected');
|
| 52 |
+
});
|
| 53 |
+
|
| 54 |
+
targetSocket.on('data', (chunk) => {
|
| 55 |
+
if (ws.readyState === ws.OPEN) ws.send(chunk);
|
| 56 |
+
});
|
| 57 |
+
|
| 58 |
+
targetSocket.on('error', () => ws.close());
|
| 59 |
+
targetSocket.on('close', () => ws.close());
|
| 60 |
}
|
| 61 |
});
|
| 62 |
|
| 63 |
+
ws.on('message', (data) => {
|
| 64 |
+
if (targetSocket && !targetSocket.destroyed) {
|
| 65 |
+
targetSocket.write(data);
|
| 66 |
+
}
|
| 67 |
});
|
| 68 |
|
| 69 |
ws.on('close', () => {
|
| 70 |
+
if (targetSocket) targetSocket.destroy();
|
| 71 |
console.log('Connection closed');
|
| 72 |
});
|
| 73 |
+
|
| 74 |
+
ws.on('error', () => ws.terminate());
|
| 75 |
});
|
| 76 |
|
| 77 |
server.listen(PORT, () => {
|
| 78 |
+
console.log(`✅ Server running on ${PORT}`);
|
| 79 |
+
console.log(`訂閱: https://${DOMAIN}/${SUB_PATH}`);
|
| 80 |
});
|