-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexec.js
More file actions
41 lines (32 loc) · 850 Bytes
/
exec.js
File metadata and controls
41 lines (32 loc) · 850 Bytes
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
const express = require('express');
const router = express.Router()
const { exec, spawn } = require('child_process');
router.post('/ping', (req,res) => {
exec(`${req.body.url}`, (error) => {
if (error) {
return res.send('error');
}
res.send('pong')
})
})
router.post('/gzip', (req,res) => {
exec(
'gzip ' + req.query.file_path,
function (err, data) {
console.log('err: ', err)
console.log('data: ', data);
res.send('done');
});
})
router.get('/run', (req,res) => {
let cmd = req.params.cmd;
runMe(cmd,res)
});
function runMe(cmd,res){
// return spawn(cmd);
const cmdRunning = spawn(cmd, []);
cmdRunning.on('close', (code) => {
res.send(`child process exited with code ${code}`);
});
}
module.exports = router