Created
April 2, 2015 09:06
-
-
Save robozevel/198f50764e547921e915 to your computer and use it in GitHub Desktop.
Express middleware method to generate a link
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 url = require('url'); | |
app.use(function(req, res, next) { | |
req.generateLink = function(pathname) { | |
return url.format({ | |
protocol: req.protocol, | |
host: req.get('Host'), | |
pathname: pathname | |
}); | |
}; | |
next(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment