Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serving specific html file in yesod

Tags:

haskell

yesod

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?

like image 496
Simon Bergot Avatar asked Mar 23 '23 02:03

Simon Bergot


1 Answers

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
like image 196
Simon Bergot Avatar answered Apr 02 '23 14:04

Simon Bergot