Custom Domain for API

Fixed. I had a couple of records for Namecheap that were for some reason redirecting to google. I still can’t use my site though, even after setting the port to what @RiversideRocks said to. I’m getting this.

I have one A record pointing to the IP of my droplet. This is the code I’m using:

const express = require("express");
const app = express();

app.use(express.static("public"));

const listener = app.listen(443, () => {
    console.log("app running")
});

app.get("/", (req, res) => {
    res.send("test")
});

Hey there, is seems like you records are messed up. Make an A record and make sure that you set the name as “@“ and set the target as the IP addressed the droplet. This should fix it. If you added “www” when connecting the domain, change the name to “www”.

2 Likes

I don’t know how custom domains work over there, I use Vultr cause it’s cheaper, but this had worked for me when I use Vultr.

1 Like

Thanks for the reply. This is what my DNS records look like on Cloudflare. americanoapi.xyz is pointed towards the IP of my droplet.

I’m not quite sure what you meant by this.

Actually, it might be an issue with the code. The PM2 process is erroring.


The folder where the code and packages are stored is called “api”.

Turn off the proxy. For instructions:

  1. Click on the record
  2. Click the orange cloud
  3. Click save.
1 Like

If that was the case, Cloudflare would send a status stating “the web server is down”

1 Like

Okay. Done. The error I’m getting is kind of nonspecific and I’m not sure what I need to fix.

The domain may not be fully transferred. Cause you would at least see a Cloudflare error.

1 Like

Cloudflare wouldn’t let me transfer the domain fully from Namecheap. It said I needed to wait 60 days before I could transfer. I could only edit the nameservers on the Namecheap dashboard to go to Cloudflare’s ones, and then Cloudflare sent me an email saying my site was activated.

Could this have anything to do with it?

This seems like a NameCheap problem more than a Cloudflare problem.

1 Like

Okay. I can afford buying another domain, since I need to get it set up asap. What domain registrar should I buy from?

Umm, I actually recommend GoDaddy. I only really have experience from them and Freenom. I never really used Freenom for production. Only downside to GoDaddy is, I found changing name servers a pain in the rear end. I was looking around for like 15 minuets before I decided to just look it up on their support page.

Thanks. I purchased one from GoDaddy and changed the Nameservers. I’m waiting for Cloudflare to detect that I pointed the Nameservers.

I restarted the Pm2 process on my ssh client, and still erroring even with the new domain, although I’m still not seeing anything in Cloudflare.

The screenshot shows running on port 8000, which doesn’t match your code above which is trying to listen to 443. Also the log shows EADDRINUSE. Try change your code to connect to port 8000

3 Likes

I noticed that, but it if you look closely, the first error is from Discord.js. And the second error is starting not null:80. Meaning that there is something wrong with how he is typing his code. Or a TypeError.

Also, port 80 is in use. Try doing pm2 stop all Then start it again.

I had actually changed it from 8000 originally to 443. I just forgot to change the log.