Created
November 8, 2010 22:13
-
-
Save Poetro/668369 to your computer and use it in GitHub Desktop.
request pass through
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'), | |
underscore = require('underscore')._, | |
httpRequest = require('request'), | |
app = express.createServer(express.logger()); | |
// For favicon requests just redirect them. | |
app.get('/favicon.ico', function (request, response) { | |
// Set the appropriate content type | |
response.writeHead(200, { | |
'Content-Type': 'image/x-icon' | |
}); | |
httpRequest({ | |
'uri' : 'http://example.com/favicon.ico', | |
'responseBodyStream': response | |
}, function (error, httpResponse, body) { | |
var length = []; | |
if (!error) { | |
length =underscore.select(httpResponse.headers, function (item, index) { | |
return index.toLowerCase() === 'content-length'; | |
}); | |
if (length.length) { | |
// Hide connect's error throwing. | |
response.headers['Content-Length'] = length[0]; | |
response.end(); | |
} | |
} | |
}); | |
}); | |
app.listen(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment