I will mention that most browsers send the port as part of the host header.
 So if you're testing locally using a custom /etc/hosts on port 8080 (or
just using port 8080 on the production machine), you'll need to account for
that in the host routing.

On Mon, Jun 4, 2012 at 10:02 AM, Oliver Leics <oliver.le...@gmail.com>wrote:

> On Mon, Jun 4, 2012 at 4:38 PM, Felix E. Klee <felix.k...@inka.de> wrote:
> > On Mon, Jun 4, 2012 at 2:51 PM, Oliver Leics <oliver.le...@gmail.com>
> > wrote:
> >> express.use(function(req, res, next) {
> >>  if(req.headers.host === 'example.com') {
> >>    res.writeHead(303, {'Location': 'http://www.example.com'+req.url})
> >>    res.end()
> >>  }
> >> })
> >
> > That made me learn a little about middleware, a new concept to me, and I
> > really like it. In the end I implemented basically what you proposed,
> > plus `next()` in the else clause.
>
> Middleware is a huge word for such a small yet powerful interface.
>
> And yes, the next() call was missing.
>
> Most nodejs code does not use the else-clause, but early return
> instead. Nicer to read, fewer to type and some benchmarks showed a
> slight speed-improvement.
>
> The code would then be like this:
>
> express.use(function(req, res, next) {
>  if(req.headers.host === 'example.com') {
>     return res.send({'Location': 'http://www.example.com'+req.url}, 301)
>  }
>  next()
> })
>
> This should be the shortest implementation according to
> http://expressjs.com/guide.html
> and .send() of express.
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nodejs@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to