We'd like to surf the internet through a node.js proxy on appfog.
We tried this code:
proxy2a.js:
var http = require('http');
var port = process.env.VCAP_APP_PORT || 8080;
console.log ('the portnumber is: '+ port) ;
http.createServer(function(request, response) {
var proxy = http.createClient(80, "checkip.dyndns.org");
var proxy_request = proxy.request(request.method, request.url, request.headers);
proxy_request.on('response', function (proxy_response) {
proxy_response.pipe(response);
response.writeHead(proxy_response.statusCode, proxy_response.headers);
console.log(proxy_response.statusCode) ;
});
request.pipe(proxy_request);
}).listen(port);
package.json:
{
"name": "proxy2a",
"author": "parker",
"version": "0.0.0-14",
"dependencies": {
},
"devDependencies": {},
"optionalDependencies": {},
"engines": {
"node": "0.6.x",
"iisnode": "*"
},
"scripts": {
"start": "node proxy2a.js"
}
}
We have the code from this question. (Actually we need the server only to access one website, so it is fine that this server only serves one.) This code works great when we run the server on our local machine.(Use node version 0.6.x.) But when we deploy to appfog, there is no reaction. (We get the ip by pinging the deploy url with another console.) Do you know how to get such a proxy server to work on appfog or any other node.js host?
Your code works exactly as-is for me. I copied your two files as-is, and ran the following commands--
af login
// enter my creds
af update testproxy
Then went to http://testproxy.aws.af.cm/ and it works. Are you sure you uploading your app correctly, are using the correct domain name, and that your app is started?
(VCAP_APP_PORT is set to 80, so your app will be running on port 80 due to this line: var port = process.env.VCAP_APP_PORT || 8080;)