Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
ebbc01d74b | |||
01e50fc8ee |
28
index.js
28
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 () {
|
(function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
var escapeHtml = require('escape-html');
|
||||||
|
|
||||||
function nowww(req, res, next) {
|
function nowww(req, res, next) {
|
||||||
var host = (req.headers.host||'').replace(/^www\./, '')
|
var host = (req.headers.host||'').replace(/^www\./, '');
|
||||||
, hostname = host.split(':')[0]
|
var hostname = host.split(':')[0];
|
||||||
, protocol = 'http' + (req.connection.encrypted ? 's' : '') + '://'
|
var protocol = 'http' + (req.connection.encrypted ? 's' : '') + '://';
|
||||||
, href = protocol + host + req.url
|
var href = protocol + host + req.url;
|
||||||
;
|
|
||||||
|
|
||||||
if (host === req.headers.host) {
|
if (host === req.headers.host) {
|
||||||
return next();
|
if (next) {
|
||||||
|
next();
|
||||||
|
} else {
|
||||||
|
res.end("Not sure what to do...");
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Permanent Redirect
|
// Permanent Redirect
|
||||||
@ -18,14 +23,7 @@
|
|||||||
res.setHeader('Location', href);
|
res.setHeader('Location', href);
|
||||||
// TODO set token (cookie, header, something) to notify browser to notify user about www
|
// TODO set token (cookie, header, something) to notify browser to notify user about www
|
||||||
res.write(
|
res.write(
|
||||||
'Quit with the www already!!! It\'s not 1990 anymore!'
|
'Redirecting to <a href="' + escapeHtml(href) + '">' + escapeHtml(hostname) + '</a>...'
|
||||||
+ '<br/>'
|
|
||||||
+ '<a href="' + href + '">' + hostname + '</a>'
|
|
||||||
+ '<br/>NOT www.' + hostname
|
|
||||||
+ '<br/>NOT ' + protocol + hostname
|
|
||||||
+ '<br/>just <a href="' + href + '">' + hostname + '</a> !!!'
|
|
||||||
+ '<br/>'
|
|
||||||
+ ';-P'
|
|
||||||
);
|
);
|
||||||
res.end();
|
res.end();
|
||||||
|
|
||||||
|
@ -18,8 +18,9 @@
|
|||||||
],
|
],
|
||||||
"contributors": [],
|
"contributors": [],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"escape-html": "^1.0.3"
|
||||||
},
|
},
|
||||||
"main": "index",
|
"main": "index",
|
||||||
"version": "1.1.4",
|
"version": "1.2.1",
|
||||||
"license": "(MIT OR Apache-2.0)"
|
"license": "(MIT OR Apache-2.0)"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user