Skip to content

Instantly share code, notes, and snippets.

@adparadise
Created November 2, 2012 22:55
Show Gist options
  • Save adparadise/4004854 to your computer and use it in GitHub Desktop.
Save adparadise/4004854 to your computer and use it in GitHub Desktop.
Proxy server, serving a local file
var mime = require('mime');
function serveLocalFile (httpRequest, httpResponse, filename) {
console.log("local: " + httpRequest.url);
var send404 = function () {
httpResponse.setHeader('Content-Type', 'text/html');
httpResponse.write("NOT FOUND: " + httpRequest.url);
httpResponse.end();
};
var existsCallback = function (exists) {
var readStream;
if (!exists) {
send404();
return;
}
httpResponse.setHeader('Content-Type',
mime.lookup(httpRequest.url));
readStream = fs.createReadStream(filename);
readStream.pipe(httpResponse);
};
fs.exists(filename, existsCallback);
};
@adparadise
Copy link
Author

No, this is designed to run in Node.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment