parent
7cea704fbb
commit
18a02a68ff
2 changed files with 34 additions and 2 deletions
@ -0,0 +1,30 @@ |
||||
const express = require('express'); |
||||
const { spawnSync } = require('child_process'); |
||||
|
||||
const router = express.Router(); |
||||
|
||||
router.get('/', (request, response) => { |
||||
console.log('Calling CLI script to get data.'); |
||||
|
||||
const childProcess = spawnSync( |
||||
'striker-access-database', |
||||
['--query', 'SELECT * FROM files;'], |
||||
{ |
||||
timeout: 10000, |
||||
encoding: 'utf-8', |
||||
}, |
||||
); |
||||
|
||||
if (childProcess.error) |
||||
{ |
||||
response.status(500); |
||||
} |
||||
|
||||
console.log('error:', childProcess.error); |
||||
console.log('stdout:', childProcess.stdout); |
||||
console.log('stderr:', childProcess.stderr); |
||||
|
||||
response.status(200).send(childProcess.stdout); |
||||
}); |
||||
|
||||
module.exports = router; |
Loading…
Reference in new issue