60

I am building a website and would not like to reconfigure the website from pointing to http://127.0.0.1 to http://www.example.com. Furthermore, the certificate that I am using is of course made with the proper domain name of www.example.com but my test environment makes calls to 127.0.0.1 which makes the security not work properly.

What I currently want to do is configure my development environment to assign the domain name www.example.com to 127.0.0.1 so that all http://www.example.com/xyz is routed to http://127.0.0.1:8000/xyz and https://www.example.com/xyz is routed to https://127.0.0.1:8080/xyz.

I am not using Apache. I am currently using node.js as my web server and my development environment is in Mac OS X Lion.

jww
  • 83,594
  • 69
  • 338
  • 732
fixedpoint
  • 1,435
  • 1
  • 16
  • 24

1 Answers1

89

If you edit your etc/hosts file you can assign an arbitrary host name to be set to 127.0.0.1. Open up /etc/hosts in your favorite text editor and add this line:

127.0.0.1   www.example.com

Unsure of how to avoid specifying the port in the HTTP requests you make to example.com, but if you must avoid specifying that at the request level, you could run nodejs as root to make it listen on port 80.

Edit: After editing /etc/hosts, you may already have the DNS request for that domain cached. You can clear the cached entry by running this on the command line.

dscacheutil -flushcache
fourk
  • 2,036
  • 15
  • 10
  • 18
    This actually doesn't answer the OP question. The port is not forwarded, and using node as root, even in development mode, is not a good idea. – Vadorequest Jan 23 '17 at 11:10