Created
March 24, 2012 17:55
-
-
Save ovaillancourt/2185619 to your computer and use it in GitHub Desktop.
Wrapping the static mw to add a custom header entry.
This file contains 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 myStatic = express.static(__dirname + '/my/static/path'); | |
app.use(function(req,res,next){ | |
//We set the custom header here. | |
res.setHeader('My-header-name','my-header-value'); | |
//We call the static middleware here, if the middleware calls "next", it means | |
//it didn't serve the file so we replace the static mw's "next" with a custom | |
//function that removes the header entry and calls the real "next" from the | |
//wrapper. This ensure we don't pollute subsequent middleware/route's response | |
//with that custom header. | |
myStatic(req,res,function(param){ | |
res.removeHeader('My-header-name'); | |
next(param); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment