PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, November 8, 2022

[FIXED] Why does NodeJs req.get('host') result to localhost:3000 on digital ocean instead of my actual domain name

 November 08, 2022     digital-ocean, express, node.js, pm2, request-headers     No comments   

Issue

I have a droplet on digital ocean. Everything works fine and is configured properly. However, I have nodeJs running on this droplet. This code req.get('host') outputs localhost:3000 instead of my domain name. Please how do i fix this, what file do i need to make this change.


Solution

I found it in the docs of expressJs. I observed digital ocean is proxying my requests, therefore adding the hostname in x-forwarded-host header property.

http://expressjs.com/en/5x/api.html#req.host

When the trust proxy setting does not evaluate to false, this property will instead get the value from the X-Forwarded-Host header field. This header can be set by the client or by the proxy.

If there is more than one X-Forwarded-Host header in the request, the value of the first header is used. This includes a single header with comma-separated values, in which the first value is used.



Answered By - Chidozie Duru
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing