I think you're looking for something like this:

// your plugin module
var http = require('http');
var originalCreateServer = http.createServer;
http.createServer = function(listener) {
  return originalCreateServer(function(req, res) {
    console.log('Intercepted request to ' + req.url);
    listener(req, res);
  });
};
// this can be in any module after your plugin module has been loaded
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337);

On Thursday, April 19, 2012 6:29:52 PM UTC+3, Masiar wrote:
>
> Thanks! That's a nice starting point. What I was wondering is: can I 
> do this as a node.js extension? Let's say a programmer already has his 
> own server created. I would like to extend whatever he did with what 
> you wrote. http.createServer won't be my choice since a server already 
> exists, right? How can I "add" those matched patterns (with relative 
> callbacks for GET/PUT/POST/DELETE) to an already created server? 
> Thanks a lot! 
>

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to