From 01e50fc8eee554031335efe4428bfebae6527b12 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 15 Jun 2018 00:58:17 -0600 Subject: [PATCH] v1.2.0 escape html and remove goofy message --- index.js | 28 +++++++++++++--------------- package.json | 2 +- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/index.js b/index.js index efa7236..aba3605 100644 --- a/index.js +++ b/index.js @@ -1,16 +1,21 @@ -/*jshint strict:true node:true es5:true onevar:true laxcomma:true laxbreak:true eqeqeq:true immed:true latedef:true undef:true unused:true*/ (function () { "use strict"; + var escapeHtml = require('escape-html'); + function nowww(req, res, next) { - var host = (req.headers.host||'').replace(/^www\./, '') - , hostname = host.split(':')[0] - , protocol = 'http' + (req.connection.encrypted ? 's' : '') + '://' - , href = protocol + host + req.url - ; + var host = (req.headers.host||'').replace(/^www\./, ''); + var hostname = host.split(':')[0]; + var protocol = 'http' + (req.connection.encrypted ? 's' : '') + '://'; + var href = protocol + host + req.url; if (host === req.headers.host) { - return next(); + if (next) { + next(); + } else { + res.end("Not sure what to do..."); + } + return; } // Permanent Redirect @@ -18,14 +23,7 @@ res.setHeader('Location', href); // TODO set token (cookie, header, something) to notify browser to notify user about www res.write( - 'Quit with the www already!!! It\'s not 1990 anymore!' - + '
' - + '' + hostname + '' - + '
NOT www.' + hostname - + '
NOT ' + protocol + hostname - + '
just ' + hostname + ' !!!' - + '
' - + ';-P' + 'Redirecting to ' + escapeHtml(hostname) + '...' ); res.end(); diff --git a/package.json b/package.json index f2e1613..e56cbe1 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,6 @@ "dependencies": { }, "main": "index", - "version": "1.1.4", + "version": "1.2.0", "license": "(MIT OR Apache-2.0)" }