Templating integration for Nunjucks (Middleware)
The middleware can be hooked into the application stack and will append a
render(status, headers, data, callback) method
to the original http response (or any kind of response which adheres to the interface defined for response in
The renderer method contains a renderer resolved based on the accept headers, which renders the passed content into an
appropriate representation for the
http protocol (properly supperted at the moment:
Currently there are only two supported renderers: HTML and JSON. The environments (
nunjucks) are application specific
and need to be passed to the middleware.
HTMLRenderer is a wrapper for nunjucks. It creates a new environment based on the domain of the request and loads
the template which has to be set on the request (in our case resolved by the
JSON.stringify and converts the passed data to a string.
The templating extensions originally provided by this package were moved to their own packages
ee-soa-extension-locale. Since environments now are passed into the middleware, the dependency is removed and extensions
are directly attached by the running application.
- Add a better loader which allows loading the templates asynchronously
- Improve handling of the mapping between the accept header and the renderer.
rendermethod of the response now directly writes the data back to the original response
- the renderers now directly write their assigned content type to the response
- the renderers directly create server errors if the rendering created an error
- therefore the API has slightly changed from
render(status, headers, data, callback)