Issue when testing from custom domain

Tell us what’s happening:
I’m able to get a correct JSON response, but outside repl my solution doesn’t seem to be registering properly (as in when I host it on my own domain). It also works in the browser.

sean@x230:~$ curl http://seance.online:3000/now
{“time”:“Thu Oct 22 2020 05:09:04 GMT+0000 (Coordinated Universal Time)”}

Your code so far
app.get(’/now’, (req,res, next)=>{
req.time = new Date().toString();
next();
}, (req,res)=>{
res.json({“time”: req.time});
});

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0.

Challenge: Chain Middleware to Create a Time Server

Link to the challenge:

Hello!

We need more information. Where is it hosted? Is it currently running? Is it accessible for everyone? Any errors? The port 3000 doesn’t seem to be open:

Starting Nmap 7.80 ( https://nmap.org ) at 2020-10-22 13:13 -03
Nmap scan report for ec2-54-200-15-39.us-west-2.compute.amazonaws.com (54.200.15.39)
Host is up (0.23s latency).
Not shown: 996 filtered ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp closed http
443/tcp closed https
3000/tcp closed ppp

1 Like

Thanks for the reply.
It’s hosted in EC2.
It’s currently running again, I’ll leave it up this time(I did a nuke and pave to rule out cruft from a previous project on the same instance). It should be accessible from anywhere (groups are 0.0.0.0/0). I’m able to curl from another ec2 instance in a separate VPC:



[ec2-user@ip ~]$ curl seance.online:3000/now
{"time":"Thu Oct 22 2020 18:14:59 GMT+0000 (Coordinated Universal Time)"}

I’m also able to use elinks to access the JSON response. I tested port connectivity with netcat as seen below:


[ec2-user@ip-172-31-55-93 ~]$ nc -zv seance.online 3000
Ncat: Version 7.70 ( https://nmap.org/ncat )
Ncat: Connected to 54.200.15.39:3000.

[ec2-user@ip-172-31-55-93 ~]$ dig seance.online +short
54.200.15.39

It’s working now.

However, did you use the boilerplate from freecodecamp or did you remove some parts? The thing is, the tests have some endpoints where they check for some things, hence if you removed them or didn’t use the boilerplate, you won’t be able to pass:

Can you share your code on github?

I’m guessing it might be the lack of HTTPS that is making the browser blocking the content on the test page.

1 Like

so I’d need to implement HTTPS in express to successfully host my test code outside repl?

Well, it needs to be served over a connection using HTTPS. I don’t really know much about EC2.

for the purposes of troubleshooting, it’s just a RHEL8 Linux VPS. So FCC can’t/won’t test over HTTP, and I need to install some LetsEncrypt certificates or something, if I understand correctly. Why wouldn’t FCC be able to do an unencrypted GET against my domain?

Did you shut it down again?

It is the browser that is blocking the mixed content, not sure if allowing “Insecure content” in the browser will work or not (Enabling mixed content).

1 Like

It’s not something that FCC does, but your browser. Technically, you could disable the restriction:

On firefox.

I didn’t shut it down, but the process did indeed die. I’ve brought it back up.

[ec2-user@ip-172-31-14-229 boilerplate-express]$ nohup npm start &
[1] 2732
[ec2-user@ip-172-31-14-229 boilerplate-express]$ nohup: ignoring input and appending output to ‘nohup.out’

[ec2-user@ip-172-31-14-229 boilerplate-express]$ netstat -tulpn | grep 3000
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp6       0      0 :::3000                 :::*                    LISTEN      2743/node           

Doesn’t seem like it works in Chrome with “Insecure content” allowed. Here is the console error as well.

Mixed Content: The page at ‘https://www.freecodecamp.org/learn/apis-and-microservices/basic-node-and-express/chain-middleware-to-create-a-time-server’ was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint ‘http://seance.online:3000/_api/chain-middleware-time’. This request has been blocked; the content must be served over HTTPS.

Once I disable this in Firefox, I’m getting ‘GET http://seance.online:3000/now/_api/chain-middleware-time’ => HTTP/1.1 404 Not Found 18ms in the console.

I appreciate everyone’s help here, I’ll probably just use REPL, I wanted to use github to track my studying progress etc. but I don’t want to get too into the weeds outside of the JS stuff.

1 Like

I haven’t really used repl.it all that much but it does have some Github integration

1 Like

I’ll look into the integrations further, thanks to both of you.

1 Like