static-file-server
static-file-server copied to clipboard
Option to redirect to root
Hi,
Do you think it would be interesting to have an option to redirect all URLs to root?
For my use case, I am currently using the static file server in a docker container to serve a maintenance page for my applications. The static file server is very handy and lightweight for that. All I have to do is spin up a container with my static maintenance page, and change the target ip address and port on my reverse proxy for the application subdomain to point to this maintenance page container, instead of the real application.
But: I also have to handle the application URLs not to produce 404 errors in the static file server. I currently handle this with URL rewriting on the reverse proxy, replacing all the URLs with /.
It would be nice to have such an option, if it can also be profitable for other users' use cases. For mine, it would be less intrusive on the reverse proxy.
Thanks a lot! Jeritiana
I like your use case. Which implementation of such a feature do you think would be more widely useful:
-
Redirect all requests to a single static file (the HTML file would either need to get CSS/JS from a different service or have it fully embedded).
-
Have an assigned file to be returned for all 404 responses.
-
Have a redirect thrown in place of a 404 to an assigned URL (possible issue with redirect loops if improperly configured?).
-
Other?
- Whatever is not a file should be left to let JS resolve it and just serve index.html. Eg. entering address http://localhost/styles.css pointing to existing file - serves it. Entering http://localhost/this/is/the/path/to/some/awesome/feature not pointing to a file or folder just serves index.html and leaves that URL in browser's address bar to let JavaScript handle it
@halverneus That is how I could use Your nice static server for SPA web app development.
@gitowiec That should be the correct way IMO - for SPA support.
@halverneus this is a pretty important issue for any JS application.
The typical implementation is to just redirect 404 errors to a 404.html page in the root of the server.
Most hosting providers do this by default: