-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbash.js
executable file
·48 lines (40 loc) · 1.21 KB
/
bash.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const express = require('express')
const app = express()
const port = 5556;
const cors = require('cors');
const { exec } = require("child_process");
const bodyParser = require('body-parser')
app.use(cors({
origin: '*'
}));
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
app.get('/', (req, res) => {
return res.status(200).json({
message: 'Service running'
})
})
app.post('/start-terminal', (req, res) => {
exec(req.body.os.indexOf('Mac') !== -1 ? `open -a Terminal.app ${req.body.command}` : `gnome-terminal -- ${req.body.command}`, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return res.status(500).json({
message: 'Something went wrong!'
})
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return res.status(500).json({
message: 'Something went wrong!'
})
}
return res.status(200).json({
message: 'Terminal started!'
})
});
})
app.listen(port, () => {
console.log(`App listening on port ${port}`)
})