http-server with localhost:3000 gives ERR_INVALID_REDIRECT

后端 未结 6 1359
半阙折子戏
半阙折子戏 2020-12-19 06:08

I have installed http-server using the following command:

npm i -g http-server

Upon running the server I get the response saying Running o

相关标签:
6条回答
  • 2020-12-19 06:18

    I changed http-server version 0.10.0 to 0.8.5 in the package.json file and it worked for me. I hope this helps someone.

    0 讨论(0)
  • 2020-12-19 06:19

    Try downgrading the http-server version as the latest version (0.10.0 and 0.11.0) is causing issue due to ecstatic (3.3.2).

    Try uninstalling the current http-server version and then try to install 0.9.0 or older version

    Uninstall

     npm uninstall -g http-server
    

    Install

    npm install http-server@0.9.0
    
    0 讨论(0)
  • 2020-12-19 06:23

    I'm having the exact same problem. Just installed both node and http-server globally. run http-server and it gives me the following error when accessing localhost:8080:

    "ERR_INVALID_REDIRECT"

    If I try to access the index.html page, it works. It doesn't even show directories listing, even with -d in the command line.

    I got something, though: installing an older version of http-server and it loads the index.html automagically :)

    This was the command/version: npm install -g http-server@0.8.5 Anything newer (0.9.0+) and it breaks again.

    Edit:

    Even then, it will only work on sub-folders, not on the root. For example:

    http://localhost:8080/mypage/ will load index.html automatically.

    http://localhost:8080/ won't

    0 讨论(0)
  • 2020-12-19 06:23

    This issue is fixed in version 0.12.0, make sure you're upgraded by running

    npm install --global http-server
    

    If you use npx http-server it should use the latest version automatically.

    0 讨论(0)
  • 2020-12-19 06:27

    pass url "0.0.0.0" when you are creating server and then try.

    0 讨论(0)
  • 2020-12-19 06:38

    This is still an open issue with http-server, which is supposedly caused by the latest version of one http-server's dependencies called ecstatic:

    https://github.com/http-party/http-server/issues/525

    There are three workarounds for this at the point:

    1. Point the browser to localhost:8080/index.html instead of just http://localhost:8080.

    2. Downgrade your http-server version to 0.9 from 10.0

      npm uninstall -g http-server
      npm install http-server@0.9.0

    3. Open package.json file under the http-server module and downgrade ecstatic dependency
      to 3.3.1 (found under 'dependencies' key).

    0 讨论(0)
提交回复
热议问题