1 | isFunction = (obj) -> '[object Function]' is toString.call obj
|
2 |
|
3 | permCode = 301
|
4 | tempCode = 302
|
5 |
|
6 | module.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()
|