OSDN Git Service

[Develop and Manual Test] show help with websocket
[eos/zephyr.git] / server / api / v1 / help / index.js
1 'use strict';
2
3 var express    = require('express');
4 var router     = express.Router()
5 var path       = require('path')
6 var ws = require(__dirname + '/../../../../server/class/WebSocket').instance;
7 var spawn = require('child_process').spawn;
8
9 var config = {
10     cwd: ''
11 };
12
13 router.get('/:command', function(req, res) {
14     var command = req.params.command;
15     var runner = spawn(command,['-h'],config);
16
17     runner.stderr.on('data', (data) => {
18         ws.emit('console', data.toString());
19     });
20
21     runner.on('close', function() {
22         res.send('/api/v1/help/'+command+' success');
23     });
24
25 });
26
27 module.exports = router;