Commits

Anonymous committed 4730a5e

Fixed proxy injection

  • Participants
  • Parent commits f6def3b

Comments (0)

Files changed (2)

src/app/controllers/proxy.coffee

 path    = require 'path'
 
 exports.request = (url)->
-	(req, res)->
+	(req, res, next)->
 		requestUrl = url + req.originalUrl
-		match      = path.extname(req.path).match /html|js|css$/
-		html       = path.extname(req.path).match /html$/
+		extname    = path.extname req.path
+		match      = extname.match /html|js|css$/
+		html       = extname in ['.html', '']
 
 		res.header 'proxied', true
 
-		if req.method is 'GET' and match?
-			req.headers['accept-encoding'] = ''
+		if req.method is 'GET' and (match? or html)
+			req.headers['Accept-Encoding'] = ''
 			req.pipe request requestUrl, (err, proxyRes, body)->
-				if html?
-					body = socket.addClientCode body
-					res.type match.toString()
-				res.send body
+				if err
+					next err
+				else
+					body = socket.addClientCode body if html
+					res.type if match then match[0] else 'html'
+					res.send body
 
 		else
 			req.pipe(request requestUrl).pipe res

src/app/controllers/socket.coffee

 
 injection = (method)->
 	(chunk, encoding)->
-		html = /html/.test @get('Content-Type')
-		if chunk and html
+		html = path.extname(@req.path) in ['.html', '']
+		if chunk? and html
 			newChunk = chunk.toString encoding
 			if newChunk.indexOf('</body>') >= 0
 				newChunk = socket.addClientCode newChunk, encoding