You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
666 B
31 lines
666 B
3 years ago
|
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;
|