Skip to content

Instantly share code, notes, and snippets.

@joaoneto
Created January 8, 2015 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joaoneto/a5a3f8953ee54cc90c3c to your computer and use it in GitHub Desktop.
Save joaoneto/a5a3f8953ee54cc90c3c to your computer and use it in GitHub Desktop.
oauthio dynamics.js
var config = require('../lib/config');
module.exports = function (hoodie) {
var dbname = config.dbname;
var oauth_cofig = hoodie.config.get('oauthio_config');
var pluginDb = hoodie.database(dbname);
var oauthio = new OauthIo(hoodie, pluginDb);
var routes = {
'get': {
config: function (request, reply) {
reply({ ok: true })
.code(200)
.type('application/json; charset=utf-8');
},
},
};
return {
// 'server.api': function (/* request, reply */) {
// console.log('server.api.* hook called', arguments);
// return true;
// },
// http://localhost:6001/_api/_plugins/oauthio/_api
'server.api.plugin-request': function (request, reply) {
// console.log('server.api.plugin-request hook called');
var method = request.method || 'get'
, params = request.params.p && request.params.p.split('/')
, body = request.payload
, query = request.query;
// console.log(method);
if (routes[method][params[0]]) {
routes[method][params[0]].call(this, request, reply);
} else {
reply(404, { error: 'notf_ound' });
}
return true;
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment