Created
December 19, 2012 04:43
-
-
Save nbqx/4334433 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var vm = require('vm'); | |
var _ = require('underscore'); | |
var src = fs.readFileSync('test.js'); | |
var code = (_.template("'use strict';(<%= src %>)(req,res)"))({src: src}); | |
var app = require('express')(); | |
app.get('/',function(req,res){ | |
var cxt = { | |
req: req, res: res, | |
console: global.console | |
}; | |
var proc = vm.createScript(code); | |
proc.runInNewContext(cxt); | |
}); | |
app.listen(3000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function(req,res){ | |
console.log(req); | |
var ret = {success: true, text: 'this is from test.js', time: new Date()}; | |
res.setHeader('Content-Type', 'application/json'); | |
res.send(ret); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment