express-dataz-context
v1.0.0
Published
A middleware which setups a Dataz context object to render data in templates
Downloads
2
Readme
Express Dataz Context
Adds an instance of Dataz onto res.locals
in an express app. This is for exposing data to the front-end of a web app.
Install
$ npm install --save express-dataz-context
Basic Usage
var express = require('express'),
context = require('express-dataz-context');
var app = express();
app.use(context);
app.get('/', function(req, res) {
// Get and add some data to the context
res.locals.context.set('someData', {
title: 'Data that needs escaping<script>alert('injection');</script>'
});
res.render('index.html');
});
/* Index Template:
<html>
<head>
<title><%= context.get('someData:title') %></title>
<script>
var pageData = <%- context.escape(true) %>;
// {"someData":{"title":"Data that needs escaping<script>alert('injection');</script>"}}
</script>
</head>
<body></body>
</html>
*/