Search code examples
haskellyesod

How do I set approot using APPROOT environment variable in yesod


I would like to set the approot value to the value from the Approot env variable in a yesod project. How do i do this? This is my main function:

appRootStatic <- (getEnv "APPROOT")    
warpEnv $ Piggies pool manager appRootStatic

The issue is that in approot function I have no way to get to the Piggies constructor as Approot is not an instance of MonadHandler?

data Piggies = Piggies { connPool :: ConnectionPool, httpManager:: Manager, staticURL :: String }

approot = do
        master <- getYesod
        ApprootMaster master (staticURL master)

I had tried ApprootStatic before i tried the ApprootMaster data constructor.

The compiler complains: "No instance for Monad Approot arising from a do statement. So my question is how to stick the value of the APPROOT variable into approot?

Thanks,


Solution

  • What you need to do is:

    1. Add a field to your foundation datatype to contain the APPROOT environment variable.
    2. Define approot in terms of ApprootMaster.
    3. In your main function, read the APPROOT environment variable and set the field in your foundation datatype.

    The scaffolding does all of this for you automatically.