moved nowww from steve to own repo
This commit is contained in:
parent
477c2e8e9c
commit
b9d113c612
57
README.md
Normal file
57
README.md
Normal file
@ -0,0 +1,57 @@
|
||||
nowww
|
||||
===
|
||||
|
||||
Redirects any domain with `www` to the same site without it.
|
||||
|
||||
* `www.foobar3000.com` -> `foobar3000.com`
|
||||
* `www.helloworld3000.com` -> `helloworld3000.com`
|
||||
|
||||
See [no-www.org][no-www.org] ![no-www.org][no-www.ico]
|
||||
|
||||
[no-www.ico]: http://no-www.org/images/blog-button.gif
|
||||
[no-www.org]: http://no-www.org
|
||||
|
||||
In short:
|
||||
|
||||
All domains should have a `www` for backwards compatibility with what
|
||||
early adopters of the internet have come to expect (and ctrl+enter adds it).
|
||||
However, those domains should redirect to the root of the domain.
|
||||
|
||||
* it means we type four fewer charaters
|
||||
* we don't type `http://` anymore, why would we type `www.`?
|
||||
* it's what the cool kids do (i.e. github)
|
||||
* `ftp`, `irc`, `ssh`, etc all have their own *protocols*. Why should the web also have a prefix?
|
||||
|
||||
Installation
|
||||
===
|
||||
|
||||
```bash
|
||||
npm install nowww
|
||||
```
|
||||
|
||||
Usage
|
||||
===
|
||||
|
||||
```javascript
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var http = require('http') // (or https / spdy)
|
||||
, connect = require('connect') // or express
|
||||
, nowww = require('./')
|
||||
, app = connect()
|
||||
, server
|
||||
;
|
||||
|
||||
app
|
||||
.use(nowww())
|
||||
.use(require('serve-static')(__dirname + '/public/'))
|
||||
;
|
||||
|
||||
server = http.createServer();
|
||||
server.on('request', app);
|
||||
server.listen(3000, function () {
|
||||
console.log('Listening on ' + server.address().port);
|
||||
});
|
||||
}());
|
||||
```
|
19
example.js
Normal file
19
example.js
Normal file
@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
var http = require('http') // (or https / spdy)
|
||||
, connect = require('connect') // or express
|
||||
, nowww = require('./')
|
||||
, app = connect()
|
||||
, server
|
||||
;
|
||||
|
||||
app
|
||||
.use(nowww())
|
||||
.use(require('serve-static')(__dirname + '/public/'))
|
||||
;
|
||||
|
||||
server = http.createServer();
|
||||
server.on('request', app);
|
||||
server.listen(3000, function () {
|
||||
console.log('Listening on ' + server.address().port);
|
||||
});
|
39
index.js
Normal file
39
index.js
Normal file
@ -0,0 +1,39 @@
|
||||
/*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";
|
||||
|
||||
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
|
||||
;
|
||||
|
||||
if (host === req.headers.host) {
|
||||
return next();
|
||||
}
|
||||
|
||||
// Permanent Redirect
|
||||
res.statusCode = 301;
|
||||
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!'
|
||||
+ '<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();
|
||||
|
||||
}
|
||||
|
||||
function create() {
|
||||
return nowww;
|
||||
}
|
||||
|
||||
module.exports = create;
|
||||
}());
|
15
package.json
Normal file
15
package.json
Normal file
@ -0,0 +1,15 @@
|
||||
{ "name": "nowww"
|
||||
, "description": "Node.JS Connect module for no-www redirection"
|
||||
, "author": "AJ ONeal <coolaj86@gmail.com> (http://coolaj86.com)"
|
||||
, "url": "http://github.com/coolaj86/connect-nowww"
|
||||
, "repository": {
|
||||
"type": "git"
|
||||
, "url": "git@github.com:coolaj86/connect-nowww.git"
|
||||
}
|
||||
, "keywords": ["nowww", "no-www", "connect", "express", "redirct", "yes-www"]
|
||||
, "contributors": []
|
||||
, "dependencies": {
|
||||
}
|
||||
, "main": "index"
|
||||
, "version": "1.1.3"
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user