baucis-decorator-env
v1.0.3
Published
Allows properties for some resource to have an alternative `development` key when accessed via `/dev/api/etc`.
Downloads
17
Maintainers
Readme
baucis-decorator-env
Allows properties for some resource to have an alternative development
key when accessed via /dev/api/etc
.
Install
npm install baucis-decorators baucis-decorator-env --save
Usage
Add the decorator and it will add the functionality to any properties containing an env
field set to true. This will allow you to access the same property in two different environments - e.g., /api/modules/123
or /dev/api/modules/123
might return different properties with this decorator enabled.
Example
controllers/Module.js
var baucis = require('baucis');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var extend = require('deep-extend');
var ResourceProps = require('../props/Resource.js');
var ResourceController = require('../controllers/Resource.js');
var ModuleProps = extend({}, ResourceProps);
ModuleProps.js = {
type: String,
env: true
};
var ModuleSchema = new Schema(ModuleProps);
var ModuleModel = mongoose.model('Module', ModuleSchema);
var ModuleController = baucis.rest('Module');
var decorators = require('baucis-decorators');
// decorate controller
decorators.add.call(ModuleController, [
'baucis-decorator-env',
ResourceController // `ModuleController` will inherit all of `ResourceController`'s decorators
]);
/**
* Expose controller.
*/
module.exports = ModuleController;