Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serve index.html by default on node http-server

Tags:

node.js

http-server dist

works great for me on '/' but when using '/foo' it returns a 404. Is there an option for this module to serve 'index.html' by default for all routes?

Or does anyone know of a similar module with this functionality? I'm looking for a server that achieve this without any code (i.e capable from the CLI entirely)

like image 607
williamsandonz Avatar asked Dec 06 '25 05:12

williamsandonz


1 Answers

You can try https://github.com/scottcorgan/pushstate-server

It works from CLI and it will server index.html for every route except your static assets

There is also a fork of http-server with implemented fallback

npm install skleeschulte/http-server --save

And then use -f or --fallback parameter:

http-server ./root -f /index.html
like image 72
Vitaly Migunov Avatar answered Dec 08 '25 17:12

Vitaly Migunov