thecoshman / http

Host These Things Please - a basic http server for hosting a folder fast and simply
MIT License
446 stars 30 forks source link

Add fallback file for SPA sites #159

Open Hona opened 9 months ago

Hona commented 9 months ago

Imagine I am using Blazor WebAssembly.

It starts from an index.html file but I would like to open a route, e.g. /mypage which the SPA can handle.

Would be nice to add an option for a fallback file.

Otherwise, I've been loving this tool ⭐

nabijaczleweli commented 9 months ago

sorry bestie i have no clue what this means

Hona commented 9 months ago

Lets say you have 3 files in the webserver

if the user routes to localhost/b.html etc it routes as usual.

Assuming there is a 'fallback' route that is configured as 'a.html', if they route to localhost/d.html (the file isn't found) then the server returns 'localhost/d.html' -> 'localhost/a.html'

more reading:

https://laraveldaily.com/post/route-fallback-if-no-other-route-is-matched https://medium.com/@codingthang/fallback-route-on-rails-e19be25383dd

nabijaczleweli commented 9 months ago

So this is "return a redirect instead of a 404"?

thecoshman commented 6 months ago

I would guess this could be added as yet another cli argumnet... you provide a file that you want to be auto-redirected to, and then a regex for what can 'detect' a 404 and instead server the redirect. This auto-redirect would obviously only kick in if the file that was directly requested wasn't found in the first place. Not sure how it would interact with serving index files.