2

I've written a Connect middleware where I'd like to re-use the "send" method of the "static" Connect middleware if it's installed. What's the best way to get a hold of that code in my middleware? Currently I'm passing the express object use "use"ing my middleware, sort of like this:

app.use(myMiddleware(express, options));

then myMiddleware calls

express.static.send(req, res, next, ...)

That works, but feels a bit clunky. Is there a better way?

Kevin Dente
  • 25,430
  • 7
  • 43
  • 47
  • What do you have currently? Can we see a gist or a github or something? Might be a need to rearchitect something. I honestly don't do Express/Connect, but I'm always willing to take a poke to see what new things I can learn – jcolebrand Jan 19 '12 at 22:04

1 Answers1

1
// myMiddleware.js
var connect = require("connect");
var send = connect.static.send

// package.json
...
"dependencies": { 
   "connect": "1.x"
}

Simply, get it directly from connect, add connect as dependency to your module.

Raynos
  • 166,823
  • 56
  • 351
  • 396