Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • kado kado
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3
    • Issues 3
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • kado
  • kadokado
  • Issues
  • #95

Closed
Open
Created Aug 27, 2020 by Bryan Tong@nullivexOwner

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.

Assignee
Assign to
Time tracking