Created
January 8, 2015 18:20
-
-
Save joaoneto/a5a3f8953ee54cc90c3c to your computer and use it in GitHub Desktop.
oauthio dynamics.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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