Spaces:
Paused

singbox / server.js
laalucas's picture
Update server.js
e7ed0f5 verified
Raw History Blame Contribute Delete
1.37 kB
const http = require('http');
const fs = require('fs');
const PORT = process.env.PORT || 7860;
const PUBLIC_IP = process.env.PUBLIC_IP || 'localhost';
const uuid = process.env.EFFECTIVE_UUID || 'subuuid';
const filePath = `/app/html/vless_links.txt`;
const server = http.createServer((req, res) => {
if (req.url === '/') {
// 首页提示信息,不暴露 UUID
res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
res.end(`🟢 恭喜!部署成功!
查看节点信息请访问: /你的UUID或/subuuid`);
} else if (req.url === `/${uuid}`) {
// 返回订阅内容
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
res.writeHead(500, { 'Content-Type': 'text/plain; charset=utf-8' });
res.end('订阅文件读取失败');
return;
}
res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
res.end(data);
});
} else {
// 其它路径返回 404 提示
res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' });
res.end(`❌ Not Found:路径错误!!!
查看节点信息请访问: /你的UUID或/subuuid`);
}
});
server.listen(PORT, () => {
console.log(`HTTP 订阅服务启动: http://${PUBLIC_IP}:${PORT}/${uuid}`);
});