Update server.js
Browse files
server.js
CHANGED
@@ -1,22 +1,28 @@
|
|
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('
|
12 |
}
|
13 |
|
14 |
exec(command, (error, stdout, stderr) => {
|
15 |
if (error) {
|
16 |
-
return res.status(500).send(`
|
17 |
}
|
18 |
if (stderr) {
|
19 |
-
return res.status(500).send(`
|
20 |
}
|
21 |
res.send(`${stdout}`);
|
22 |
});
|
|
|
|
|
1 |
const express = require('express');
|
2 |
const { exec } = require('child_process');
|
3 |
+
const path = require('path');
|
4 |
const app = express();
|
5 |
const port = 7860;
|
6 |
|
7 |
+
// Middleware to parse URL-encoded bodies
|
8 |
+
app.use(express.urlencoded({ extended: true }));
|
9 |
+
|
10 |
+
// Serve static files (HTML, CSS, JS)
|
11 |
+
app.use(express.static(path.join(__dirname, 'public')));
|
12 |
+
|
13 |
app.get('/run', (req, res) => {
|
14 |
const command = req.query.command;
|
15 |
|
16 |
if (!command) {
|
17 |
+
return res.status(400).send('Please provide a command.');
|
18 |
}
|
19 |
|
20 |
exec(command, (error, stdout, stderr) => {
|
21 |
if (error) {
|
22 |
+
return res.status(500).send(`Error: ${error.message}`);
|
23 |
}
|
24 |
if (stderr) {
|
25 |
+
return res.status(500).send(`Output: ${stderr}`);
|
26 |
}
|
27 |
res.send(`${stdout}`);
|
28 |
});
|