module.exports = function shtmlEmulator(json, template) {

    return function(req, res, next) {
        //var Buffer = require('buffer').Buffer;
        var WritableStream = require("stream-buffers").WritableStreamBuffer;

        var buffer = new WritableStream();

        var oldWrite = res.write;
        res.write = function(chunk) {
            buffer.write(chunk);
            return true;
        };

        var oldEnd = res.end;
        
        res.end = function(data) {
			var context = this;
		
            if(data) {
                buffer.write(data);
            }

            if (!buffer.size()) {
                return oldEnd.call(context, buffer.getContents());
            }

            var body = buffer.getContentsAsString();
            
            try {
                body = template.process(body, json);
            } catch (e) {
                console.log('An error occurred while processing a template (' + e.message + ').');
            }
            
            oldEnd.call(context, body);
        };

        next();
    };
};

@@ -102,10 +102,8 @@
     
-//
 var 
@@ -137,16 +137,16 @@
 Buffer;%0A
+
         
@@ -258,17 +258,119 @@
 ream();%0A
+        %0A        if(req.url != %22/%22 && !req.url.match(/%5C.s?html$/))%0A            return next();%0A        
 %0A
-
         
@@ -533,25 +533,16 @@
 es.end;%0A
-        %0A
         
@@ -572,11 +572,20 @@
 ) %7B%0A
-%09%09%09
+            
 var 
@@ -604,10 +604,8 @@
 is;%0A
-%09%09
 %0A   
@@ -848,43 +848,9 @@
 ();%0A
-            
 %0A
-            try %7B%0A    
     
@@ -891,153 +891,25 @@
 dy, 
-json);%0A            %7D catch (e) %7B%0A                console.log('An error occurred while processing a template (' + e.message + ').');%0A            %7D
+%7B data: json %7D);%0A
 %0A   
@@ -917,28 +917,22 @@
         
-%0A           
+return
  oldEnd.
@@ -952,16 +952,17 @@
  body);%0A
+%0A
         

implement config file