|
|
@ -28,7 +28,7 @@ app.get('/', function(req, res){ |
|
|
|
res.render('tests'); |
|
|
|
}); |
|
|
|
|
|
|
|
app.post('/render', function(req, res, next){ |
|
|
|
function testFn(req){ |
|
|
|
// Normalize state.png as ./public/state.png
|
|
|
|
// no good way around this at the moment
|
|
|
|
req.body.fn = req.body.fn |
|
|
@ -36,10 +36,18 @@ app.post('/render', function(req, res, next){ |
|
|
|
.replace("'face.jpeg'", "'" + __dirname + "/public/face.jpeg'"); |
|
|
|
|
|
|
|
// Do not try this at home :)
|
|
|
|
var fn = eval('(' + req.body.fn + ')') |
|
|
|
, width = req.body.width |
|
|
|
, height = req.body.height |
|
|
|
, canvas = new Canvas(width, height) |
|
|
|
return eval('(' + req.body.fn + ')'); |
|
|
|
} |
|
|
|
|
|
|
|
function createCanvas(req, type){ |
|
|
|
var width = req.body.width |
|
|
|
, height = req.body.height; |
|
|
|
return new Canvas(width, height, type); |
|
|
|
} |
|
|
|
|
|
|
|
app.post('/render', function(req, res, next){ |
|
|
|
var fn = testFn(req) |
|
|
|
, canvas = createCanvas(req) |
|
|
|
, ctx = canvas.getContext('2d') |
|
|
|
, start = new Date; |
|
|
|
|
|
|
@ -55,6 +63,24 @@ app.post('/render', function(req, res, next){ |
|
|
|
: fn(ctx), done(); |
|
|
|
}); |
|
|
|
|
|
|
|
app.post('/pdf', function(req, res, next){ |
|
|
|
req.body = JSON.parse(req.body.json); |
|
|
|
var fn = testFn(req) |
|
|
|
, canvas = createCanvas(req, 'pdf') |
|
|
|
, ctx = canvas.getContext('2d'); |
|
|
|
|
|
|
|
function done(){ |
|
|
|
res.writeHead(200, {'Content-Type' : 'application/pdf'}); |
|
|
|
res.write(canvas.toBuffer()); |
|
|
|
res.end(); |
|
|
|
} |
|
|
|
|
|
|
|
2 == fn.length |
|
|
|
? fn(ctx, done) |
|
|
|
: fn(ctx), done(); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
var port = parseInt(process.argv[2] || '4000', 10); |
|
|
|
app.listen(port); |
|
|
|
console.log('Test server listening on port %d', port); |
|
|
|