Update index.js
Browse files
index.js
CHANGED
|
@@ -4,10 +4,10 @@ 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 |
|
|
@@ -15,7 +15,7 @@ const requestHandler = (req, res) => {
|
|
| 15 |
if (req.url === '/') {
|
| 16 |
fs.readFile(path.join(__dirname, 'index.html'), (err, content) => {
|
| 17 |
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
| 18 |
-
res.end(err ? '<h1>
|
| 19 |
});
|
| 20 |
}
|
| 21 |
else if (req.url === `/${SUB_PATH}`) {
|
|
@@ -24,7 +24,7 @@ const requestHandler = (req, res) => {
|
|
| 24 |
|
| 25 |
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
| 26 |
res.end(base64);
|
| 27 |
-
console.log('
|
| 28 |
}
|
| 29 |
else {
|
| 30 |
res.writeHead(404);
|
|
@@ -35,21 +35,33 @@ const requestHandler = (req, res) => {
|
|
| 35 |
const server = http.createServer(requestHandler);
|
| 36 |
const wss = new WebSocketServer({ server });
|
| 37 |
|
| 38 |
-
wss.on('connection', (ws) => {
|
| 39 |
-
console.log('New
|
|
|
|
| 40 |
ws.once('message', (data) => {
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
}
|
| 50 |
});
|
| 51 |
|
| 52 |
-
ws.on('error', () =>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
});
|
| 54 |
|
| 55 |
server.listen(PORT, () => {
|
|
|
|
| 4 |
const { WebSocketServer } = require('ws');
|
| 5 |
|
| 6 |
// =============== 修改這裡 ===============
|
| 7 |
+
const UUID = 'b831381d-6324-4d53-ad4f-8cda48b30811'; // 你的 UUID
|
| 8 |
+
const DOMAIN = 'wky-tty.hf.space'; // 你的 HF 域名
|
| 9 |
+
const WSPATH = 'ws'; // WS 路徑
|
| 10 |
+
const SUB_PATH = 'sub'; // 訂閱路徑
|
| 11 |
const PORT = 7860;
|
| 12 |
// ========================================
|
| 13 |
|
|
|
|
| 15 |
if (req.url === '/') {
|
| 16 |
fs.readFile(path.join(__dirname, 'index.html'), (err, content) => {
|
| 17 |
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
| 18 |
+
res.end(err ? '<h1>Hugging Face Proxy</h1>' : content);
|
| 19 |
});
|
| 20 |
}
|
| 21 |
else if (req.url === `/${SUB_PATH}`) {
|
|
|
|
| 24 |
|
| 25 |
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
| 26 |
res.end(base64);
|
| 27 |
+
console.log('✅ 訂閱被請求');
|
| 28 |
}
|
| 29 |
else {
|
| 30 |
res.writeHead(404);
|
|
|
|
| 35 |
const server = http.createServer(requestHandler);
|
| 36 |
const wss = new WebSocketServer({ server });
|
| 37 |
|
| 38 |
+
wss.on('connection', (ws, req) => {
|
| 39 |
+
console.log('New WS Connection');
|
| 40 |
+
|
| 41 |
ws.once('message', (data) => {
|
| 42 |
+
const buf = Buffer.from(data);
|
| 43 |
+
|
| 44 |
+
// VLESS 協議簡單回應(版本 0)
|
| 45 |
+
if (buf[0] === 0) {
|
| 46 |
+
const response = Buffer.from([0x00, 0x00]); // VLESS 成功回應
|
| 47 |
+
ws.send(response);
|
| 48 |
+
console.log('VLESS Handshake OK');
|
| 49 |
+
}
|
| 50 |
+
// Trojan 簡易處理
|
| 51 |
+
else if (buf.length > 56) {
|
| 52 |
+
ws.send(Buffer.from([0x01, 0x00]));
|
| 53 |
+
console.log('Trojan Handshake');
|
| 54 |
}
|
| 55 |
});
|
| 56 |
|
| 57 |
+
ws.on('error', (err) => {
|
| 58 |
+
console.log('WS Error:', err.message);
|
| 59 |
+
ws.terminate();
|
| 60 |
+
});
|
| 61 |
+
|
| 62 |
+
ws.on('close', () => {
|
| 63 |
+
console.log('Connection closed');
|
| 64 |
+
});
|
| 65 |
});
|
| 66 |
|
| 67 |
server.listen(PORT, () => {
|