mirror of
https://github.com/jimeh/heartb.it.git
synced 2026-02-19 12:56:47 +00:00
turned the redirect thing into a loadable host_redirect middleware
This commit is contained in:
@@ -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
|
||||
|
||||
7
src/middleware/host_redirect.coffee
Normal file
7
src/middleware/host_redirect.coffee
Normal 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()
|
||||
Reference in New Issue
Block a user