I am trying to setup a server with a static file route, a webservice api, and the home address at the root of the domain. My yesod app looks like this:
mkYesod "App" [parseRoutes|
/static StaticR Static getStatic
/ HomeR GET
... api routes
|]
Now I found how to serve static files and how to handle api requests. But I am stuck for the getHomeR
definition. I would simply like to serve an index.html
file. I could manually read it and pass it as a string. But is there an efficient built-in solution for serving a specific html file?
Well, I found the answer 1 minute after asking (I had been searching for 20 minutes).
There is a nice helper in Yesod.Handler
called sendFile
. The getHomeR
definition looks like this:
getHomeR :: Handler ()
getHomeR = do
app <- getYesod
let indexPath = getRootDir app </> "index.html"
sendFile "text/html" indexPath
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With