Permalink
Browse files

Redirect www subdomain of Blot's site to apex domain

  • Loading branch information...
davidmerfield committed Jan 8, 2019
1 parent 425a805 commit 4013a6c604a7fb5daf897d7060a2e5e134a0d4d5
Showing with 28 additions and 1 deletion.
  1. +7 −1 app/blog/vhosts.js
  2. +21 −0 app/index.js
@@ -9,7 +9,7 @@ module.exports = function(req, res, next) {
if (!host) {
err = new Error("No blog");
err.code = "ENOENT";
next(err);
return next(err);
}

// Cache the original host for use in templates
@@ -20,6 +20,12 @@ module.exports = function(req, res, next) {
// the main blot site so leave now.
if (host === config.host) return next();

// Redirect www subdomain of main blot site to
// the apex domain on which it is served.
if (host === 'www.' + config.host) {
return res.redirect(req.protocol + "://" + config.host + req.url);
}

handle = extractHandle(host);

if (handle) {
@@ -34,6 +34,27 @@ var sessionOptions = {
})
};

// Blot's SSL certificate system requires the existence
// of the domain key in redis. See config/nginx/auto-ssl.conf
// for more information about the specific implementation.
// Anyway, so that the homepage. We redirect the 'www' subdomain
// to the apex domain, but we need to generate a cert to do this.
// Typically, domain keys like domain:example.com store a blog's ID
// but since the homepage is not a blog, we just use a placeholder 'X'
redis.mset(
["domain:" + config.host, "X", "domain:www." + config.host, "X"],
function(err) {
if (err) {
console.error(
"Unable to set domain flag for host" +
config.host +
". SSL may not work on site."
);
console.error(err);
}
}
);

// Prevent IE users from executing
// downloads in your site's context
// Prevent some browsers from

0 comments on commit 4013a6c

Please sign in to comment.