The node-horseman works perfectly on my local server, but when I put it on azure it does not work. Node-horseman is a headless-browser module for node.js. I think the azure is blocking access from external links, but how could I unlock this?
const Horseman = require('node-horseman');
const users = ['PhantomJS', 'nodejs'];
var express = require('express'),
http = require('http'),
app = express();
app.get('/', function (req, res) {
res.send("Deu certo!");
console.log("Funcionou");
});
app.get('/twitter/', function (req, res) {
var retorno = ``;
var extracoes = 0;
console.log("aqui");
users.forEach((user) => {
const horseman = new Horseman();
horseman
.open(`http://twitter.com/${user}`)
.text('.ProfileNav-item--followers .ProfileNav-value')
.then((text) => {
retorno += `${user}: ${text}<br>`;
extracoes ++;
if (extracoes == users.length) {
res.send(retorno);
}
})
.close();
});
});
app.set('port', process.env.PORT || 3000);
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
If you're hosted on Azure App Service, be aware of this wiki here - https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#unsupported-frameworks
Deploy your application to Cloud Services or a VM instead. App Service on Linux should also work if you bring your own container (with PhantomJS and all dependencies).