middleware-render

1.0.0 • Public • Published

render middleware

middleware to render arbitrary views. This middleware can be used with all existing template engines.

Usage

Middleware called before render should populate the req.loaded object with data that the view should present to the client render will send the output of view req.loaded to the client

Example

jsonView = (params) -> JSON.stringify params

router.get '/resource',
    (req, res, next) ->
        req.loaded =
            foo: 'bar'
            fitz: [1..10]
        next()
    render jsonView

// will render `'{"foo":"bar","fitz":[1,2,3,4,5,6,7,8,9,10]}'` to the
// client

Credits

This middleware was implemented with snd while hacking together on a project. I cleaned up the code and added some tests.

Readme

Keywords

none

Package Sidebar

Install

npm i middleware-render

Weekly Downloads

0

Version

1.0.0

License

none

Last publish

Collaborators

  • mren