Skip to content

Instantly share code, notes, and snippets.

@catarak
Last active April 25, 2017 02:44
Show Gist options
  • Save catarak/7d7b8f336b88a72d32e2a9fcbe235f83 to your computer and use it in GitHub Desktop.
Save catarak/7d7b8f336b88a72d32e2a9fcbe235f83 to your computer and use it in GitHub Desktop.
module.exports = function api(options) {
var validActions = { add:'add' }
this.add('role:api,path:todo', function (msg, respond) {
var action = msg.args.params.action;
var todoText = msg.args.body.text;
this.act('role:todo', {
cmd: validActions[action], // do this to prevent injection attacks
text: text,
}, respond);
});
this.add('init:api', function (msg, respond) {
this.act('role:web',{ routes: {
prefix: '/api',
pin: 'role:api,path:*',
map: {
todo: { POST: true, suffix:'/:action' }
}
}}, respond);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment