Created
June 2, 2014 18:00
-
-
Save pc-rgundlapalli/dbfed4a124fe59f6bfde to your computer and use it in GitHub Desktop.
node version of cpages.php
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 captoraUtils = {}; | |
captoraUtils.getLandingPage = function(req, res, next){ | |
logger.debug('getLandingPage', landingPage) | |
var CAPTORA_PAGES_PREFIX = 'http://cdn.captora.com/pages/personalcapital.com/v1/html/', | |
CAPTORA_PAGES_DEFAULT = 'https://www.personalcapital.com', | |
CAPTORA_PAGES_TIMEOUT = 10, | |
landingPage = req.params.pageName, | |
responseStream = ''; | |
// make a request to captora for the corresponding page name | |
var http = require('http'); | |
var requestUrl = CAPTORA_PAGES_PREFIX + landingPage; | |
// make the request | |
var httpRequest = http.request(requestUrl, function(httpResponse) { | |
// callback for response | |
logger.debug('getLandingPage response statusCode ' + requestUrl, httpResponse.statusCode); | |
if(httpResponse.statusCode == 200){ | |
httpResponse.on('data', function (chunk) { | |
responseStream += chunk; | |
}); | |
httpResponse.on('end', function () { | |
res.send(responseStream); | |
}); | |
}else { | |
next(); | |
} | |
}); | |
// end the request | |
httpRequest.end(); | |
// request error handler | |
httpRequest.on('error', function(err) { | |
logger.error('getLandingPage exception', err.stack); | |
}); | |
}; | |
captoraUtils.getRelatedLinks = function(req, res, next){ | |
logger.debug('getRelatedLinks', srcPageUrl) | |
var CAPTORA_PAGES_PREFIX = 'https://widgets.captora.com/wserver/?key=c07b0f79ffdafc857520fb362b3484b7&domain=personalcapital.com&url=', | |
srcPageUrl = req.query.srcPageUrl | |
responseStream = ''; | |
// make a request to captora for the corresponding page name | |
var https = require('https'); | |
var requestUrl = CAPTORA_PAGES_PREFIX + encodeURIComponent(srcPageUrl); | |
// make the request | |
var httpRequest = https.request(requestUrl, function(httpResponse) { | |
// callback for response | |
logger.debug('getRelatedLinks response statusCode ' + requestUrl, httpResponse.statusCode); | |
if(httpResponse.statusCode == 200){ | |
httpResponse.on('data', function (chunk) { | |
responseStream += chunk; | |
}); | |
httpResponse.on('end', function () { | |
res.send(responseStream); | |
}); | |
} | |
}); | |
// end the request | |
httpRequest.end(); | |
// request error handler | |
httpRequest.on('error', function(err) { | |
logger.error('getRelatedLinks exception', err.stack); | |
}); | |
} | |
module.exports = captoraUtils; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment