Package Exports
- sharify
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (sharify) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
sharify
Easily share data between your server-side and browserify modules.
Example
Given an express app with jade.
- Add middleware
app.use(sharify({
API_URL: 'http://artsy.net/api/v1',
NODE_ENV: process.env.NODE_ENV
}));- Inject script and use data in template if you want
html
body
#scripts
//- Make sure this is above your other scripts
!= sharifyScript
script( src='/bundle.js' )
//- `sd` is short hand for sharify.data
if sd.NODE_ENV == 'production'
include ./google-analytics.html- Use in browserify/server-side modules
var sd = require('sharify').data;
module.exports = function Artwork(id) {
this.url = sd.API_URL + '/artwork/' + this.id;
};Dynamic and request level data
Sharify also accepts a function that passes in the request object so you can easily pass dynamic or request level data to client-side modules.
app.use(sharify(function(req) {
return {
SESSION_ID: req.session.id,
USER_AGENT: req.headers['user-agent'],
AB_TEST: Math.random() > 0.5 ? 'A' : 'B'
}
});Contributing
Please fork the project and submit a pull request with tests. Install node modules npm install and run tests with make test.
License
MIT