Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I serve index.html by default in my http-server

I have created a basic AngularJS app in node environment. I am using http-server module for serving the files to browser. Everything is working fine except for the fact that I can't get to serve index.html by default when the server launches.

I checked out npm registry for more options to http server module, and also tried looking for a relevant question on SO but still not able to get what I desire.

Is it possible at all to specify the file to pick up while server starts.

My server basically starts at localhost:8080 while I would like localhost:8080/index.html

My start script is http-server -a localhost -p 8080 -c-1. If I do something like http-server -a localhost -p 8080 -c-1 index.html, to my surprise it opens the index.html file but serves it on file protocol and not on localhost.

What am I doing wrong here.

P.S. I visited Angular JS seed and there official example says http-server -a localhost -p 8080 -c-1 ./app. However, when I do this I get error Windows can't find specified path, although my structure is similar to the seed.

My structure:

dir
   --app.js
   --index.html
   --node_modules
   --package.json
like image 893
Saurabh Tiwari Avatar asked Apr 23 '17 11:04

Saurabh Tiwari


People also ask

How do I run Index html?

Make sure you have chrome installed. Right click on the index. html file you want to open, choose open with (which will give you a list of programs), choose chrome. There are ways to set defaults when opening files but that depends on personal preference.

Why is index html not working?

If you've just placed an index. html or index. php file on your server's document root folder, for example: /public_html/ and you're still not getting it to load these files upon a request to your domain, chances are your server is missing a specific configuration for the "DirectoryIndex Directive".

Where should I put my index html?

Using your text editor, create a new file called index. html and save it just inside your test-site folder. images folder: This folder will contain all the images that you use on your site.

What is the index html file?

The index. html page is the most common name used for the default page shown on a website if no other page is specified when a visitor requests the site. In other words, index. html is the name used for the homepage of the website.


1 Answers

Make sure you are building your project first and generating an output ./dist folder or similar.

Then try this command instead:

http-server -p 8080 ./dist -o http://localhost:8080/index.html

You are missing the http:// in your url.

like image 77
Elliott Avatar answered Sep 16 '22 17:09

Elliott