forked from MrSwitch/node-oauth-shim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (26 loc) · 757 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//
// Implement oauth-shim with a webservice
//
var oauthshim = require('./src/oauth-shim');
var url = require('url');
oauthshim.listen = function(server, requestPathname) {
// Store old Listeners
var oldListeners = server.listeners('request');
server.removeAllListeners('request');
server.on('request', function(req, res) {
// Lets let something else handle this.
// Trigger all oldListeners
function passthru() {
oldListeners.forEach(function(handler) {
handler.call(server, req, res);
});
}
// If the request is limited to a given path, here it is.
if (requestPathname && requestPathname !== url.parse(req.url).pathname) {
passthru();
return;
}
oauthshim.request(req, res);
});
};
module.exports = oauthshim;