IIS can't read data (HTTP GET requests) from node.js app - node.js

I hired a VPS (Windows Server 2008) with the aim of hosting a website.
So i configured IIS 7.5 to run a html website.
The website reads data (HTTP GET requests) from a little node.js application running on the same VPS on port 3000.
On the other hand, for every GET call i am getting:
failed to load resource the server responded with a status of 404 (not found)

Ok my fault. I needed to change the http request from
$.get( "/myfunction", function( data ) {
});
to
$.get( "http://localhost:3000/myfunction", function( data ) {
});

Related

Why is my HttpPlatformHandler server app getting HTTP Error 502.3 Bad Gateway

I'm writing a HttpPlatformHandler server app with C++ and Winsock functions. It works great on my development machine but when deployed on other machines it fails. I can run it separately and access it from the browser using the default port I coded into it on those other machines. Here are the error details:
Web Browser:
HTTP Error 502.3 Bad Gateway
Error Code 0x80070057
There was a connection error while trying to route the request.
Event Viewer:
HttpPlatformHandler
Process '0' failed to start. Port = 19516, Error Code = '-2147024809'.
I figured it out. I had the web.config file in a subfolder under C:\inetpub\wwwroot with the file in the URL. I moved it to C:\inetpub\wwwroot and now it works.

ECONNRESET http client node.js

I have a node.js app, which test uptime of websites.
I'm using HTTP client library 'request' (https://www.npmjs.com/package/request) to scan my differents websites but from one client of mine, I frequently get error :
ECONNRESET
All other domains (hundreds of them) are working fine. This client is using incapsula CDN.
The app is running in a docker EC2 cluster in AWS. I tried to switch today to another HTTP client library 'Axios' (https://www.npmjs.com/package/axios) but still the same error.
Any idea on how can I get a solution ?
You've to manage network error:
devices down
host unreachable
service on host unreachable
service on host restarted (TCP connexion broken)
Here is a part of a code to do this:
Connexion.on('error', (err) => {
console.log(" Disconnected. Velbus reusedSocket:",Connexion.reusedSocket, " err.code:", err.code)
if (Connexion.reusedSocket && err.code === 'ECONNRESET') {
// retriableRequest();
}
});
Late answer but if that could help others...

jsreport Hello world

I'm trying to create my first report with jsreport. I've followed the documentation, but I'm not able to generate the most simple Hello world.
I've tried:
npm install jsreport
and then create a simple server:
var http = require('http');
var jsreport = require('jsreport');
http.createServer(function (req, res) {
jsreport.render("<h1>Hello world</h1>").then(function(out) {
out.stream.pipe(res);
}).catch(function(e) {
res.end(e.message);
});
}).listen(1337, '127.0.0.1');
The server is running on port 1337.
But if I try to open http://localhost:1337/ nothing happens. I was expecting a page with Hello world.
On the server side, I get on the console:
2018-02-17T10:55:16.009Z - info: Initializing jsreport#1.10.0 in development mode using configuration file: jsreport.config.json
2018-02-17T10:55:16.011Z - info: Setting process based strategy for rendering. Please visit http://jsreport.net/learn/configuration for information how to get more performance.
2018-02-17T10:55:16.013Z - info: Searching for available extensions in /home/jgr/WebstormProjects/GeoMasterBoard/server/
2018-02-17T10:55:16.016Z - info: Extensions location cache not found, crawling directories
Do I need a jsreport server running or this code should be enough?
I also tried to install jsreport server, following the documentation.
After jsreport start it shows on the console:
2018-02-17T10:42:46.013Z - info: Initializing jsreport#1.10.0 in development mode using configuration file: jsreport.config.json
2018-02-17T10:42:46.015Z - info: Setting process based strategy for rendering. Please visit http://jsreport.net/learn/configuration for information how to get more performance.
2018-02-17T10:42:46.023Z - info: Searching for available extensions in /home/jgr/WebstormProjects/GeoMasterBoard/server/
2018-02-17T10:42:46.025Z - info: Extensions location cache not found, crawling directories
But nothing happens when I try to open http://localhost:5488/. If I do: nmap -p 5488 localhost the awnser is:
PORT STATE SERVICE
5488/tcp closed unknown
What am I missing?
I'm using node.js v8.1.2, on Ubuntu 16.04.
your code is not working because the following reasons:
when you open your browser at http://localhost:1337/ your browser is actually making 3 different requests (1-> http://localhost:1337/, 2-> http://localhost:1337/favicon.ico, 3-> http://localhost:1337/robots.txt), not just one
the code that your are using to handle the http server is not doing a proper routing, it should process a url just once, right now it is just calling jsreport.render on every single request that goes through your server (even the ones for /favicon.ico, /robots.txt), and this is bad in the browser because as i already explained your browser makes like 3 request for a single page load.
you are using the shortcut jsreport.render in the request handling, which means that jsreport is going to try to initialize itself when your first request arrives, because of the problem explained above (not doing a proper routing in your http server) this results in jsreport trying to initialize 3 times on your first page load which leads to an uncaught exception that exits your process with no error message (we are going to update some things to better handling this exception in the future).
finally, here is some code that completes your hello world test case (with some code that filters unwanted requests like /robots.txt, /favicon.ico, but in production code you should implement a proper router logic in your http server. if you don't want to code it yourself just use something like express)
var http = require('http');
var jsreport = require('jsreport');
http.createServer(function(req, res) {
if (req.url !== '/') {
return console.log('ignoring request:', req.url);
}
console.log('request:', req.url);
jsreport
.render('<h1>Hello world</h1>')
.then(function(out) {
out.stream.pipe(res);
})
.catch(function(e) {
res.end(e.message);
});
}).listen(1337, '127.0.0.1');

Node http requests not going through proxy

We are currently building a desktop application in node-webkit and we need to send http requests to a remote server. For this we decided to use request, a http wrapper module for node.
This works fine on all but one of our machines. The code for the download looks a bit like this:
var options = {
url: url
};
request.post(options
, function (error, response, body)
{
if (!error && response.statusCode == 200)
{
cb && cb(null, body);
}
}
).on('error', function (err)
{
}).pipe(writeStream);
So with this the result we get on my machine is this:
On our network here the proxy server is 172.24.8.14 and my address is 172.24.9.130. Node sent the request through the proxy server wich contacted the target server. The result that is sent back is a 301 which is expected.
...And on the other machine:
This time Node attempted to send the request directly to the target server. This resulted in the proxy blocking the request completely.
The strange thing is that we do not specify a proxy in our code however the requests do seem to go through the proxy...but not on the other machine.
Is there some reason for this? How is node somehow detecting the proxy and sending the request to the proxy?
The reason for this turned out to be that our network was using an NTLM proxy which required ISA client to be running on our machines but it was not running on the other machine. Installing ISA client on that machine allowed traffic to go through the proxy as normal.

Azure 502 web server received an invalid response while acting as a gateway

I started getting random 502 errors on my page. Is this connected with Azure or my website? I didn't do any changes since Thursday, so I am little skeptical about being my code.
502 - Web server received an invalid response while acting as a gateway or proxy server. There is a problem with the page you are looking for, and it cannot be displayed. When the Web server (while acting as a gateway or proxy) contacted the upstream content server, it received an invalid response from the content server.
I was checking the logs, but all it says is at which url it happens, and it happens on main root page.
In my case this happened because of an infinite loop in the code, which was only triggered in production but not on my local machine. Fixing the infinite loop obviously fixed the 502. ;-)
Update: Meta-example of the infinite loop (C#).
public IList<Model> PropertyOne
{
get
{
return !_productionOnlyCondition ? _models.ToList() : PropertyTwo;
}
}
public IList<Model> PropertyTwo
{
get
{
return PropertyOne.Where(model => model.Condition).ToList();
}
}

Resources