mirror of
https://github.com/schroinerxy/Sing-box.git
synced 2026-06-22 04:35:49 +08:00
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
const http = require('http');
|
|
const fs = require('fs');
|
|
const exec = require("child_process").exec;
|
|
const subtxt = './sub.txt'
|
|
const PORT = process.env.PORT || 3000;
|
|
|
|
// Run start.sh
|
|
fs.chmod("start.sh", 0o777, (err) => {
|
|
if (err) {
|
|
console.error(`start.sh empowerment failed: ${err}`);
|
|
return;
|
|
}
|
|
console.log(`start.sh empowerment successful`);
|
|
const child = exec('bash start.sh');
|
|
child.stdout.on('data', (data) => {
|
|
console.log(data);
|
|
});
|
|
child.stderr.on('data', (data) => {
|
|
console.error(data);
|
|
});
|
|
child.on('close', (code) => {
|
|
console.log(`child process exited with code ${code}`);
|
|
console.clear()
|
|
console.log(`App is running`);
|
|
});
|
|
});
|
|
|
|
// create HTTP server
|
|
const server = http.createServer((req, res) => {
|
|
if (req.url === '/') {
|
|
res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
|
|
res.end('Hello world!');
|
|
}
|
|
// get-sub
|
|
if (req.url === '/sub') {
|
|
fs.readFile(subtxt, 'utf8', (err, data) => {
|
|
if (err) {
|
|
console.error(err);
|
|
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
res.end(JSON.stringify({ error: 'Error reading sub.txt' }));
|
|
} else {
|
|
res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
|
|
res.end(data);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
server.listen(PORT, () => {
|
|
console.log(`Server is running on port ${PORT}`);
|
|
});
|