Skip to content

Instantly share code, notes, and snippets.

@dnkm
Created July 2, 2016 07:22
Show Gist options
  • Save dnkm/8b54dda9898003072fdf7e44d9bee2fd to your computer and use it in GitHub Desktop.
Save dnkm/8b54dda9898003072fdf7e44d9bee2fd to your computer and use it in GitHub Desktop.
Photo Proxy Server
/*
Simple web server that proxies a remote image
run: simple-server . $PORT
*/
var http = require('http');
var url = require('url');
var request = require('request');
const PORT = 8100;
function handleRequest(req, res) {
var path = req.url;
if (path == "/alive") {
res.end("alive");
return;
}
var reg = /\w*\.(jpg|gif|png)/i
var matches = reg.exec(path);
if (matches == null) {
res.end("invalid filename");
} else {
var filename = matches[0];
var uri = "http://image.mammababy.lifenstats.com.s3-website-us-west-2.amazonaws.com/"+filename;
res.setHeader("Content-Type", "image/png");
request.get(uri).pipe(res);
}
}
var server = http.createServer(handleRequest);
server.listen(PORT, function() {
console.log("server running...");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment