Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

issues #997 code review #1160

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
3 participants

ipiyer commented Jun 5, 2012

I added a method to req object which will help to build a absolute uri.

@tj tj commented on the diff Jun 5, 2012

lib/request.js
@@ -132,6 +132,19 @@ req.acceptsLanguage = function(lang){
};
+/**
+ * Builds absolute uri from req,
+ * Example: http://localhost/foo
+ *
+ * @param {String} host
+ * @return {String}
+ * @api public
+ */
+
+req.buildAbsoluteUri = function(host) {
+ return this.protocol + '://' + (host || this.get('host')) + this.path;
@tj

tj Jun 5, 2012

Owner

it's a bit tricky because there are a few things I would want to include ideally. I think the most common use would probably be adding a pathname and query-string via object or string, something like req.buildUrl('/foo', { sort: 'asc' }), but even then im not sure it belongs in Express unless we can come up with a better API for a few reasons. one) it looks weird, two) it would require that people do stuff like res.redirect(req.buildUrl('/path', req.query)) which kinda sucks if they want to retain a query-string

Member

jonathanong commented Sep 10, 2013

can no longer merge. we can move this to the discussion visionmedia#1377

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment