http-party / http-server

a simple zero-configuration command-line http server
MIT License
13.66k stars 1.5k forks source link

404 fallback to index.html #385

Closed arthurkhlghatyan closed 7 years ago

arthurkhlghatyan commented 7 years ago

Hi there! I need to fallback not found routes to my index.html file for react-router to work properly. I saw many related issues here but none of them are solved. Please pay attention to this feature because it's needed a lot.

Thanks.

rdebeasi commented 7 years ago

For reference, here's how Harp implements this feature: http://harpjs.com/docs/development/200-ok

[Edit] Looks like this feature is actually covered in #80.

arthurkhlghatyan commented 7 years ago

Thanks, @rdebeasi, right now I'm using serve package. It has an option called -s which is redirecting 404 routes to index.html automatically.

BigBlueHat commented 7 years ago

@arthurkhlghatyan as you've found many other packages already do this and some of them exist solely too offer this "fallback" system.

Generally sending the same HTML content and a 200 in response to any request made to your server breaks the Web (conceptually) and limits the browsers ability to help you via catching, prefetching, 304 Not Modified, and other things that make for performance friendly sites.

Consequently, since its handled in other dedicated packages that are OK with that approach, I'd recommend anyone interested in that feature use those. This project is dedicated to being an HTTP server, so...always returning 200 isn't useful.

Cheers, 🎩