Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Redirecting from naked domain to www with node/express?

Received: by 10.68.241.71 with SMTP id wg7mr159950pbc.8.1338820775502;
        Mon, 04 Jun 2012 07:39:35 -0700 (PDT)
X-BeenThere: nodejs@googlegroups.com
Received: by 10.68.240.165 with SMTP id wb5ls14014511pbc.1.gmail; Mon, 04 Jun
 2012 07:39:26 -0700 (PDT)
Received: by 10.68.234.38 with SMTP id ub6mr10707423pbc.2.1338820766245;
        Mon, 04 Jun 2012 07:39:26 -0700 (PDT)
Received: by 10.68.234.38 with SMTP id ub6mr10707422pbc.2.1338820766234;
        Mon, 04 Jun 2012 07:39:26 -0700 (PDT)
Return-Path: <fe...@f76.eu>
Received: from mail-pb0-f43.google.com (mail-pb0-f43.google.com [209.85.160.43])
        by gmr-mx.google.com with ESMTPS id iq5si1036974pbc.1.2012.06.04.07.39.26
        (version=TLSv1/SSLv3 cipher=OTHER);
        Mon, 04 Jun 2012 07:39:26 -0700 (PDT)
Received-SPF: neutral (google.com: 209.85.160.43 is neither permitted nor denied by best guess record for domain of fe...@f76.eu) client-ip=209.85.160.43;
Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 209.85.160.43 is neither permitted nor denied by best guess record for domain of fe...@f76.eu) smtp.mail=fe...@f76.eu
Received: by pbcwz7 with SMTP id wz7so5634271pbc.2
        for <nodejs@googlegroups.com>; Mon, 04 Jun 2012 07:39:26 -0700 (PDT)
        d=google.com; s=20120113;
        h=mime-version:sender:x-originating-ip:in-reply-to:references:from
         :date:x-google-sender-auth:message-id:subject:to:content-type
         :x-gm-message-state;
        bh=8zlXcd4WBCYpsWhZI/wUlS5vWQ0WytINlDCkuuWrbEk=;
        b=nkjEKpiD0AKKWQ4zQXrs4uxGO8cLhRm4eRT4sqNqmyA9tUVtqHqICnikojL0zUbJY8
         sPAmx2lrbSBF0aD+/ZQv3bJTNbkecf8MWkDFtvgykV8hnQe8JtHXXfHtA2T+sguMCyrJ
         sOs2uX6f4OO2DaFmRLgtU6+2GF7IQJX7M8ev+ctjPBSVmLgsHlKc2QW50F/x1cGDn0kh
         XZ+OI8m4Ym3lJmPh3oC1+PcJwhHfJWggDeTSyWxL3hxu6++UiLWT3mCXzzmmoiYBjMVc
         3z/NnuhYNYO12PSxWkyyW6DFkQJWcWr3hhpmFekmN+yq5+/l7A5WNONB9wKUzZpbWDTw
         PJPw==
Received: by 10.68.237.74 with SMTP id va10mr40103456pbc.46.1338820765842;
 Mon, 04 Jun 2012 07:39:25 -0700 (PDT)
MIME-Version: 1.0
Sender: fe...@f76.eu
Received: by 10.68.201.2 with HTTP; Mon, 4 Jun 2012 07:38:55 -0700 (PDT)
X-Originating-IP: [87.164.216.103]
In-Reply-To: <CAOYEtUX746bpc8TyVdMQAThxqcRt3T8bT_yxwkjNQ4P_H-y...@mail.gmail.com>
References: <13deb259-0045-46ea-9857-09fae9afd...@c19g2000yqk.googlegroups.com>
 <CALmFrqQRw69zNZZvGne=oauaWADAHt+9O97E8kEq-Wxrz+e...@mail.gmail.com>
 <CA+m_8J2qpLinE=gy3wv3gW-0E1B9ZwizO+vvxyHZs1P4W2b...@mail.gmail.com> <CAOYEtUX746bpc8TyVdMQAThxqcRt3T8bT_yxwkjNQ4P_H-y...@mail.gmail.com>
From: "Felix E. Klee" <felix.k...@inka.de>
Date: Mon, 4 Jun 2012 16:38:55 +0200
Message-ID: <CA+m_8J1g3hhMeyUODNAUZhsVKEXz32FN2Y=Qx41MA9y+2d=...@mail.gmail.com>
Subject: Re: [nodejs] Redirecting from naked domain to www with node/express?
To: nodejs@googlegroups.com
Content-Type: text/plain; charset=ISO-8859-1
X-Gm-Message-State: ALoCoQlMmoFxOv4BAn9bh/8uxe1zR0tfuLh8BdgQE0qi0NVfqZN52WIeAPvSOHRbGHYs/pc8Y27W

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.