Last active
February 13, 2016 12:06
-
-
Save yangshun/b97410373f0d3038936d to your computer and use it in GitHub Desktop.
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
// "body-parser": "^1.4.3", | |
// "express": "^4.4.5", | |
// "request": "^2.67.0" | |
var fs = require('fs'); | |
var path = require('path'); | |
var express = require('express'); | |
var bodyParser = require('body-parser'); | |
var app = express(); | |
var http = require('http'); | |
var https = require('https'); | |
var request = require('request'); | |
app.set('port', (process.env.PORT || 3000)); | |
app.use('/', express.static(path.join(__dirname, 'public'))); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({extended: true})); | |
app.get('/image', function(req, response) { | |
var options = { | |
hostname : 'fbcdn-profile-a.akamaihd.net', | |
path : '/hprofile-ak-xfa1/v/t1.0-1/p50x50/11825118_10153549492513308_7678611442138423030_n.jpg?oh=072963cf06ac46e1f13b43390af6dcff&oe=56EB8D31&__gda__=1458976696_832979896ee76af9cec44c19c9fe034d', | |
method : 'GET' | |
}; | |
var hreq = https.request(options, function(res) { | |
console.log("statusCode: ", res.statusCode); | |
console.log("headers: ", res.headers); | |
var data = []; | |
res.on('data', function(d) { | |
data.push(d); | |
}); | |
res.on('end', function() { | |
data = Buffer.concat(data); | |
response.writeHead(200, { 'Content-Type': 'image/jpg' }); | |
response.end(data, 'binary'); | |
}); | |
}); | |
hreq.end(); | |
hreq.on('error', function(e) { | |
console.error(e); | |
}); | |
}); | |
app.listen(app.get('port'), function() { | |
console.log('Server started: http://localhost:' + app.get('port') + '/'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment