Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

changing the name of localhost web app express?

I'm working on a project, and I NEED to change the name of the project from localhost:9000 to someothername:9000, this is in my development environment, not production.

I was given the project files, and the person (who is no longer here) used express.js. I've searched and searched for the answer to this, but I cannot figure it out.

So, is it possible to change the name of localhost:9000 to someothername:9000 using express.js or updating the gruntfile? I know that I can change the localhost settings on my computer, but I need for there to be an alias that occurs through the web application.

I'm ready to rip my hair out. :(

like image 667
webDeverJr Avatar asked Nov 12 '15 20:11

webDeverJr


2 Answers

as you are on development environment, its enough to add

127.0.0.1  testurl.test

on the bottom of

C:\Windows\System32\drivers\etc\hosts

now to set the port of the server to 80 (standartport for http) you need to change

project\bin\www

(ejs standart line 15)

var port = normalizePort(process.env.PORT || '3000');

to

var port = normalizePort(process.env.PORT || '80');

now, if you type testurl.test in your browser, it should show you the website.

this works for windows, if you have an mac or linux, just change the hosts file as you need.

Marius

like image 85
AbGeMarst Avatar answered Sep 26 '22 10:09

AbGeMarst


You can't change that from within express. The domain name is resolved by the browser using OS system and DNS services. It is not resolved by your express application. It is resolved by the browser before any connection to your express application is made.

You could edit the host file on your local computer to define someothername as an alias for localhost. How exactly you edit the host file depends upon what OS you are running as this is an OS-specific feature.


Just to review, here's the normal steps when you request a web page in the browser.

  1. User requests a specific URL in a browser.
  2. Browser parses the domain out of the URL and requests a DNS lookup of that domain using local TCP-based services on the host OS.
  3. The host OS looks at the domain requested to see if it is a hostname that it recognizes or has a cached entry for.
  4. If it does recognize the hostname or has a cache entry for it, then an IP address corresponding to that hostname is returned back to the browser.
  5. If it does not recognize the hostname, then the local computer contacts a DNS server to lookup the IP address and returns that IP address back to the browser.
  6. Once the browser has the IP address, it makes a TCP connection to that IP address on the desired port number.
  7. If the IP address corresponds to your Express server, then this is the first time that your Express server is even involved in the process.
like image 32
jfriend00 Avatar answered Sep 24 '22 10:09

jfriend00