Skip to content

Instantly share code, notes, and snippets.

@jiangzhuo
Last active January 8, 2016 15:30
Show Gist options
  • Save jiangzhuo/fb61ddd9c1bb0cba6b30 to your computer and use it in GitHub Desktop.
Save jiangzhuo/fb61ddd9c1bb0cba6b30 to your computer and use it in GitHub Desktop.
UpdateFuncWithSB.js
var vm = require('vm');
var util = require('util');
var express = require('express');
var bodyParser = require('body-parser');
var multer = require('multer'); // v1.0.5
var upload = multer(); // for parsing multipart/form-data
var app = express();
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({extended: true})); // for parsing application/x-www-form-urlencoded
app.get('/', function processFunc(req, res) {
res.send('Hello What!');
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
app.post('/helloWhat', upload.array(), function (req, res) {
var helloWhat = "app._router.stack[4].route.stack[0].handle=function (req, res) {res.send('Hello %s!');}";
var context = {
app: app,
require: require
};
try {
vm.runInNewContext(util.format(helloWhat, req.body.what), context);
res.send('helloWhat res');
} catch (e) {
res.send('helloWhat err res');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment