1.0.0 • Published 9 years ago

express-dataz-context v1.0.0

Weekly downloads
1
License
ISC
Repository
github
Last release
9 years ago

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&lt;script&gt;alert('injection');&lt;/script&gt;"}}
		</script>
	</head>
	<body></body>
</html>
*/