DEV Community

Discussion on: PM2 listening on port 443 shows EADDRINUSE: address already in use :::443

Collapse
 
dmahely profile image
Doaa Mahely

Hello Rong and thanks for your input.

So you mean something like this:
example.com sends a GET request to api.example.com which redirects to api.example.com:3000?

I need the frontend calls to go to port 443 on the Express server because I had an SSL error when trying to do requests directly to api.example.com:3000, I assumed because I'm not allowed to make an insecure request from a secure website.

Collapse
 
motss profile image
Rong Sen Ng • Edited

Your redirect is not what the redirect I was talking about. What I meant was to redirect all unsecured HTTP requests to secured HTTPS requests. If you are able to do that, your express app won't need to listen to port 80 or 443 whatsoever.

Your express app should work with IP addresses and ports only. The picture would look like this:

user visits (https)api.example.com --- your load balancer or any proxy in between that should accepts only listen to port 80 and 443 will route to your express app --- reroute traffic to express app at :3000 --- your express app at port 3000 will process the request

For redirect, it looks like this:

User visit (http)example.com --- your proxy asks browser to go to (https)example.com --- browser visits (https)example.com again --- proxy allows and reroute to your express app.

So it's more of your proxy between the internet and your express app. For that people might use nginx or equivalent to do that. You might have something simpler depends on your cloud service provider.

Thread Thread
 
dmahely profile image
Doaa Mahely

Ah yes, I got your point. I had HTTP to HTTPS redirection set up already but needed the extra step of redirecting from 443 to 3000 where the endpoints lived.

I got it working eventually, thanks for your time!