With our templating system working, let's go ahead and hook all of this up to our server. Instead of now responding with a simple message of A okay!, we will respond with our template all put together. We can do this easily by running the following code:
stream.respond({
'content-type': 'text/html',
':status': 200
});
const file = fs.createReadStream('./template/main.html');
const tStream = new LoopingStream({
dir: templateDirectory,
vars : { //removed for readability }
},
loopAmount : 2
})
file.pipe(tStream).pipe(stream);
});
This should look almost exactly like our test harness. If we now head to https://localhost:50000, we should see a very basic HTML page, but we have our templated file created! If we now head into the development tools and look at the sources...