Render middleware
It would be nice to do some post processing within the render stack itself on an application basis.
For example: when requests are made in JSON it would be advantageous to simply send the response in JSON based on the variables being sent to the template. However there has to be some measure of control over the data being sent. There has to be greater care in what data is sent through a JSON request as it may expose portions of the Model system that were not intended.
Also language packs and other post processing can happen in this stage rather than directly in the controller. Allowing for a my systematic approach to internationalization (which I consider part of serving in computer oriented languages also).
Consider the following App code.
// add a view engine
const viewFolder = fs.path.join(__dirname, '..', 'view')
const viewEngine = new View.ViewMustache(viewFolder)
viewEngine.use((req, res, view, params) => {
if (!req.isJSON) return // continue normal rendering
res.json(params)
return true // signal true to stop normal processing and finish
})
app.view.addEngine('mustache', viewEngine)
app.view.activateEngine('mustache')
This would add a post rendering middleware to automatically send template params directly to the request maker using JSON.
There could be many other usages and a useful hook point being directly within the view engine.