turned the redirect thing into a loadable host_redirect middleware

This commit is contained in:
2011-12-25 09:51:42 +00:00
parent 533cf0822b
commit 349e9eaef6
4 changed files with 30 additions and 14 deletions

View File

@@ -8,11 +8,6 @@ app.configure ->
app.set 'views', __dirname + '/views'
app.set 'view engine', 'coffee'
app.register '.coffee', require('coffeekup').adapters.express
app.use (req, res, next) ->
if req.header('Host') == 'www.heartb.it'
res.redirect('http://heartb.it/')
else
next()
app.use express.bodyParser()
app.use express.methodOverride()
app.use express.static(__dirname + '/public')
@@ -21,7 +16,9 @@ app.configure 'development', ->
app.use express.errorHandler(dumpExceptions: true, showStack: true)
app.configure 'production', ->
app.use express.errorHandler
app.use express.errorHandler()
app.use require('./middleware/host_redirect')
"www.heartb.it": "http://heartb.it"
# Routes

View File

@@ -0,0 +1,7 @@
module.exports = (redirect_map = {}) ->
(req, res, next) ->
host = req.header('Host')
if redirect_map[host]
res.redirect(redirect_map[host])
else
next()