Simplify logic now that we're not redirecting safe paths

This commit is contained in:
Phoenix Eliot 2016-09-06 16:24:40 -07:00
parent bdabee865c
commit b08c1af038

View file

@ -58,23 +58,11 @@ setupDomainFilterMiddleware = (app) ->
/^\/web-dev-iframe\.html$/
/^\/javascripts\/web-dev-listener\.js$/
]
serveFromBoth = [
/^\/healthcheck$/ # Allow the load balancer to check if we're up yet
/^\/javascripts\/workers\/aether_worker\.js$/
/^\/javascripts\/app\/vendor\/aether-html\.js$/
/^\/file\/db\/thang.type\/[a-f0-9]+\/.*$/
/^\/images\/.*$/
]
app.use (req, res, next) ->
domainRegex = new RegExp("(.*\.)?(#{config.mainHostname}|#{config.unsafeContentHostname})")
domainPrefix = req.host.match(domainRegex)?[1] or ''
if _.any(serveFromBoth, (pathRegex) -> pathRegex.test(req.path))
next()
else if _.any(unsafePaths, (pathRegex) -> pathRegex.test(req.path))
if req.host isnt domainPrefix + config.unsafeContentHostname
res.redirect('http://' + domainPrefix + config.unsafeContentHostname + req.path)
else
next()
if _.any(unsafePaths, (pathRegex) -> pathRegex.test(req.path)) and (req.host isnt domainPrefix + config.unsafeContentHostname)
res.redirect('http://' + domainPrefix + config.unsafeContentHostname + req.path)
else
next()