feat(striker-ui-api): add files route

main
Tsu-ba-me 3 years ago
parent 7cea704fbb
commit 18a02a68ff
  1. 6
      striker-ui-api/app.js
  2. 30
      striker-ui-api/routes/files.js

@ -3,12 +3,14 @@ const path = require('path');
const API_ROOT_PATH = require('./lib/consts/API_ROOT_PATH'); const API_ROOT_PATH = require('./lib/consts/API_ROOT_PATH');
const echoRoute = require('./routes/echo'); const echoRouter = require('./routes/echo');
const filesRouter = require('./routes/files');
const app = express(); const app = express();
app.use(express.json()); app.use(express.json());
app.use(path.join(API_ROOT_PATH, 'echo'), echoRoute); app.use(path.join(API_ROOT_PATH, 'echo'), echoRouter);
app.use(path.join(API_ROOT_PATH, 'files'), filesRouter);
module.exports = app; module.exports = app;

@ -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…
Cancel
Save