haskell-servant / haskell-servant/servant
How do you serve an index.html file as fallback route?
- Dominant language
- Haskell
- Stars
- 2k
- Forks
- 427
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 5
Description
I am trying to (loosely) re-implement a toy CRUD SPA originally written with React + Express, this time using Halogen (PureScript) and servant.
In my original version, I had Express serve some REST API behind http://localhost:port/api/...
A catchall fallback is used to serve `static/index.html`.
In the meanwhile, the client-side uses the History API for routing.
WIth that as motivation, I would like to implement something similar with servant. Things I have tried:
* `serveDirectoryWebApp "static"`: This does not work of course, unless you explicitly navigate to `http://localhost:port/index.html`.
* `serveDirectoryFileServer "static"`: This will serve `index.html` from `/`, because of the underlying `ssIndices` property. Still won't behave like a catchall handler.
* `serveDirectoryWith . myOwnSettings`: Specifically, by matching manually inside `ssFileLookup`.
The last option gives you all the control you need I think, but it's a) easy to screw up, and b) probably not how you're supposed to use servant. Technically I'm using `wai-app-static` at this point.
Regarding a), if you simply serve `index.html` for everything, the `` element will in turn fetch `index.html` again. With Express, this worked out of the box, but now I have to decide if I should match against `app.js`, or add a 404 handler, or ...
So how should I approach this idomatically?
Contributor guide
Assessment
This issue has not been assessed yet.