modify connect.static responses

I want the functionality of connect.static, but I want to inject code into any HTML and JavaScript files that are served.

  1. Can I hook into connect.static to modify the data it serves?
  2. Is there a better approach?

connect.static isn't the right choice for this. The static middleware is specifically for serving static content directly from disk.

Look at connect-assetmanager (https://github.com/mape/connect-assetmanager), it has a serveModify hook that should do what you're needing.