johnpapa / lite-server

Lightweight node server
MIT License
2.31k stars 267 forks source link

Is there a way to change Hostname? #139

Open kenanyildiz opened 6 years ago

kenanyildiz commented 6 years ago

Hello everyone,

I want to change hostname on lite-server but i did not find any way to do is on lite-server.

from: http://localhost:3000 to: http://127.0.0.1:8080

Thanks.

zatchgordon commented 6 years ago

Please keep in mind localhost is the same thing as 127.0.0.1 This means the only difference is the number after the colon (3000 vs 8080) a.k.a. the port number.

If you would like to change the port number, or any other settings, you can create a liteServer.config.js file. Inside this file you can place the code

{
  "port": 8000,    /* Change this port number to whatever you want e.g. 8080 */
  "files": ["./src/**/*.{html,htm,css,js}"],  /* maybe try removing the "/src" part of the path */
  "server": { "baseDir": "./src" } /* maybe try changing this to {"baseDir": "./"} => point to where you code is being loaded from */
}

Next, when running lite-server via the console you can run the command lite-server -c liteServer.config.js. You can name the config file whatever you would like and place it in whatever folder you would like. In the README file it suggests to put your config in a config folder. I keep it in the base folder.

After running the command you should be able to go to either http://127.0.0.1:8080 orhttp://localhost:8080.

mikeerickson commented 6 years ago

I have a similar need, as when I am working at Starbucks, the server wont start unless I use 127.0.0.1 Is there an alternate way of starting the server where accessing as localhost actually works?