Create server.js
Browse files
server.js
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// server.js
|
2 |
+
const express = require('express');
|
3 |
+
const { exec } = require('child_process');
|
4 |
+
const app = express();
|
5 |
+
const port = 7860;
|
6 |
+
|
7 |
+
app.get('/run', (req, res) => {
|
8 |
+
const command = req.query.command;
|
9 |
+
|
10 |
+
if (!command) {
|
11 |
+
return res.status(400).send('No command provided');
|
12 |
+
}
|
13 |
+
|
14 |
+
exec(command, (error, stdout, stderr) => {
|
15 |
+
if (error) {
|
16 |
+
return res.status(500).send(`Error: ${error.message}`);
|
17 |
+
}
|
18 |
+
if (stderr) {
|
19 |
+
return res.status(500).send(`Stderr: ${stderr}`);
|
20 |
+
}
|
21 |
+
res.send(`<pre>${stdout}</pre>`);
|
22 |
+
});
|
23 |
+
});
|
24 |
+
|
25 |
+
app.listen(port, () => {
|
26 |
+
console.log(`Server running at http://localhost:${port}`);
|
27 |
+
});
|