EC2- non responding http requests - http

I just installed my node.js app in a windows micro instance with security group quick-start and with http port enabled.
I opened the firewall in the instance and opened port 80, 443 for inbound and outbound both.
In spite of that, my http requests are not being honored by the node.js app.
From log I see that the app is connected to redis and mongo and socket.io is also started.
What's wrong ? why http requests are blocked ?

Have you by chance built your app on top of the Example Webserver as currently shown on the Node.js home page as well? The sample currently looks like so:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
Either way your Node.js server might simply not be listening on the correct port/hostname combination - the Example Webserver listens on port 1337 (rather than the regular HTTP port 80) and on localhost only (rather than on the private/internal IP address which has been assigned to your EC2 instance) for example.
If these assumptions apply, you could achieve you goal by adjusting the listen() statement accordingly, see my answer to the related question Node.js Amazon EC2 example webserver - no result for an extended discussion, including a couple of variations regarding the flexible use of the server.listen(port, [hostname], [callback]).
Good luck!

Finally found the problem.
I introduced log4js and integrated this with express, as,
app.use(log4js.connectLogger(logger, { level: log4js.levels.ERROR }));
This created the problem. Somehow this was failing. Looks like it works only with DEBUG. After commenting this, it started working. Strange !!

Related

Deno Server doesn't go through the Internet

I built a simple Webserver with just the serve function from the std http module. It just redirects a request to a new URL:
import { serve } from "https://deno.land/std#0.120.0/http/server.ts";
serve(req => Response.redirect("https://google.com"))
It works, when I access the server through a browser on my laptop, where the server is running, but when I try to access it on another machine in the same network using the ip-address of my laptop, there simply is no response at all. Is this one of the security features Deno has and if so, how can you deactivate it?
Update:
So I tried looking up the requests I make on my local machine in Wireshark, but when I run the server and send a request, it doesn't show up there. I disabled my Wifi Connection to see if that changes anything and to my surprise, I still got an answer from the server when I sent a request through the browser. I came to the conclusion that the Deno server somehow doesn't serve over the local network which really confuses me. Is there a way to change that behaviour?
This is not related to Deno, but rather the firewall features of your device/router/network or an error in the method that you are using to connect from the other device (typo, network configuration, etc.).
Without additional configuration (by default), serve binds to 0.0.0.0:8000, so — as an example — if your laptop is assigned the local address 192.168.0.100 by your router, you could reach the server at the address http://192.168.0.100:8000.
You might want to do research on SE/NetworkEngineering and elsewhere to determine the cause of the blocked connection.

How to reach a restrserve api from rstudio server on aws?

I am trying out the very interesting package RestRserve from with RStudo server that I installed on an AWS instance.
This is de code I use:
library(RestRserve)
app = Application$new()
app$add_get(
path = "/hello",
FUN = function(request, response) {
response$set_body("Hello from RestRserve")
})
backend = BackendRserve$new()
backend$start(app, http_port = 8080)
I think the app is up and running, the message seems right:
{"timestamp":"2020-01-26 07:42:30.957686","level":"INFO","name":"Application","pid":1872,"msg":"","context":{"http_port":8080,"endpoints":{"HEAD":"/hello","GET":"/hello"}}}
-- running Rserve in this R session (pid=1872), 2 server(s) --
(This session will block until Rserve is shut down)
However, when I try to reach the app using the ip address of the instance like this: http://35.180.45.129/hello the browser says the site can't be reached.
Did I miss something? Any ideas about why this doesn't work?
Likely you need two additional steps:
make sure you allow traffic from internet to 8080 port
make sure you use public IP (or better DNS) of your instance

SignalR self hosting with owin

I want to create an signalr app that will be self hosted using Owin, so to start off i tried to run the sample that is on https://github.com/SignalR/SignalR/wiki/Self-host. But when i run the application and then navigate to /signar/hubs i get a 500 Server error. I get the same exception when i try to connect from my client app.
Do i need to add something else apart from what is in the sample code? or does anyone know of a good tutorial?
Things to check if trying to access from an external connection:
Are you hosting the server on all addresses or just localhost?
// use http://*:8080 to bind to all addresses.
string url = "http://localhost:8080";
Make sure to run app as administrator.
Also, is the Windows firewall blocking the port you are using? I had to add an exception to allow incoming TCP connections on that port.

Can't access port 8080 on EC2 (AWS)

I just started a new AWS EC2 instance. In the instance's security group I added a new rule to open port 8080. I also stopped the iptables service on the instance, per another post. So in theory this port should be wide open.
I started my RESTful service on 8080 and was able to access it locally via curl.
When I come in with curl remotely I get an error saying it couldn't connect to the host.
What else should I check to see if 8080 is truly open?
I started my RESTful service on 8080 and was able to access it locally via curl.
What kind of technology is your RESTful service based upon?
Many frameworks nowadays listen on localhost (127.0.0.1) only, be it by default or by means of their examples, see e.g. the canonical Node.js one (I realize that port 8080 hints towards Java/Tomcat, anyway):
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
The log message generated by starting this is Server running at http://127.0.0.1:1337/ - the emphasized part is key here, i.e. the server has been configured to listen on the IP address 127.0.0.1 only, whereas you are trying to connect to it via your public Amazon EC2 IP Address.

Unable to obtain tokenresult oauthClient.ExchangeCodeForAccessToken; unreachable network 69.171.229.24:443

I developed an FBConnect web application using C# .Net Framework 4.0 recently. Tested with my UAT server, everything just works fine, I'm able to login with my Facebook account, and perform all operation.
Unfortunately when I deploy the same code to my client's production environment, the FBConnect return "unreachable network 69.171.229.24:443". After several investigation, notice the port 443 is blocked! And due to corporate policy, this port is not allowed!!
Is there alternate way I can tweak my facebook app settings NOT to authenticate via port 443? instead of rewriting my code?
Please advice.
No, there is no alternative.
Port 443 is for secure HTTPS connections using TLS and SSL. Facebook, quite correctly, restricts access to their authentication mechanism to this port: (as far as I know) there are no alternative mechanisms that use a different port or an insecure login on port 80.
Check with your client to see if there's an proxy server that can be used for HTTPS connections.
Otherwise, request that your client opens that port.

Resources