1.0.0 • Published 8 years ago
FrontJSON v1.0.0
FrontJSON
Express middle-ware that allows config to be created in our app, and then presented to the front end.
Example
If you wanted to tell your front end code the domain of an API and the theme to use, you could set it using FrontJSON - and it would be delivered to your front end app.
Add FrontJSON to your app
var express = require('express');
var front = require('frontjson');
app.use(front.deliver);
To set a theme in the global namespace
front.set('theme', 'redandpurple');
To set a domain within an 'api' namepace
var apiConfig = front.namespace('api');
apiConfig.set('domain', 'api.example.com');
Now, if you go to your root and call /config.json it will be delivered as:
{
"theme": "readandpurple",
"api": {
"domain": "api.example.com"
}
};
1.0.0
8 years ago