Rendered data doesn't write correctly to HTTP stream.
Closed this issue · 1 comments
courtney-miles commented
I'm finding that writing data to a HTTP response stream stops after the first replacement.
This is the code to replicate:
var http = require('http');
var mu = require("mu2");
http.createServer(function(req, res) {
mu.clearCache("helloMsg");
mu.compileText("helloMsg", "<p>Hello, {{name}}.</p>");
mu.render("helloMsg", {name: "John"}).on('data', function(data) {
var asString = data.toString();
console.log(asString);
res.write("<body>"+asString+"</body>");
res.end();
});
}).listen(8888);
HTTP output (note that ".
" has been stripped):<body><p>Hello, </body>
Console output:
<p>Hello,
John
.</p>
I'm using Node.js v0.10.5 on Linux Mint and mu2 is reported as version 0.5.17.
raycmorgan commented
The 'data' event may be called multiple times. Look for the 'end' event to know when to end the http res.
res.write('<body>');
mu.render("helloMsg", {name: "John"}).on('data', function(data) {
res.write(data);
}).on('end', function () {
res.write('</body>');
res.end();
});
- Sorry in advance if there are typos