UNPKG

491 Btext/coffeescriptView Raw
1isFunction = (obj) -> '[object Function]' is toString.call obj
2
3permCode = 301
4tempCode = 302
5
6module.exports = (location, permanent = false) -> (req, res) ->
7 statusCode = if permanent then permCode else tempCode
8 loc = location
9 loc = loc req if isFunction loc
10 isBack = loc is 'back'
11 loc = req.url if isBack
12 loc = req.headers.referer if isBack and req?.headers?.referer?
13 console.log "redirect to #{loc}"
14 res.writeHead statusCode, {Location: loc}
15 res.end()