support for execution of async functions + integration with backend through server.exec()

This commit is contained in:
azivner
2018-01-23 21:59:30 -05:00
parent 27cb6b1c4d
commit f439969962
4 changed files with 32 additions and 3 deletions

19
routes/api/script.js Normal file
View File

@@ -0,0 +1,19 @@
"use strict";
const express = require('express');
const router = express.Router();
const auth = require('../../services/auth');
const wrap = require('express-promise-wrap').wrap;
const log = require('../../services/log');
router.post('/exec', auth.checkApiAuth, wrap(async (req, res, next) => {
log.info('Executing script: ' + req.body.script);
const ret = await eval("(" + req.body.script + ")()");
log.info('Execution result: ' + ret);
res.send(ret);
}));
module.exports = router;