Http-server: it does not work when i reload the browser after navigating to a route.

Created on 25 Apr 2019  路  8Comments  路  Source: http-party/http-server

In angular 7, On running the dist on local machine , for the first time web page is loading. And when on reloading or hit the url, the page throwing the error.

I am used this link to run on the local machine

How to run the Dist Folder on Local Machine in Angular 6?

On Reload and for hit the url I am using .htaccess file. but Its not work.

I took the template build with command ng build --prod

I changed in index.html href="/browser/"

For run on the local machine I am used http-server.

First install the package globally using command

npm install http-server -g.

Then inside the project directory(in the terminal) just run

http-server dist/.
For the first time web page is loading on the local machine and when on reloading or hit the url, the page throwing the server error.

needs-more

Most helpful comment

@thornjad Great, it works with SPA:

http-server --gzip --proxy http://localhost:8080?

All 8 comments

@NikitaPooja what is the error you're getting?

Also, .htaccess is a configuration file for the Apache server, http-server won't read it.

I got the same. It does not support SPA.

@rofrol could you share the error you're seeing?

No error, it just does not direct you to index.html for routes. This works for me with nginx:

events {
    worker_connections 768;
}

http {
    server {
        # Enable static gzip
        gzip_static on;

        listen 8080 default_server;
        listen [::]:8080 default_server;

        root /home/user/projects/project1;

        location / {
            try_files $uri /index.html;
        }
    }
}

@rofrol you are correct that http-server does not support fallback paths in the manner of try_files. However, you can use 404.html to sort-of support SPA. See #318 and #80.

@NikitaPooja is the error you're seeing when you say "the page throwing the server error" actually a 404 error, or is it an actual server error?

@thornjad Great, it works with SPA:

http-server --gzip --proxy http://localhost:8080?

Oh yes that's a good hack too! We've got that coming into the README in #513!

Proxy redirect is now documented in the readme, as added by #513

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  4Comments

dKab picture dKab  路  7Comments

jondlm picture jondlm  路  6Comments

Altiano picture Altiano  路  7Comments

dumptyd picture dumptyd  路  4Comments