summaryrefslogtreecommitdiff
path: root/Foundation.hs
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2017-03-14 01:19:36 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2017-03-14 01:19:36 +0100
commit53fcf55c02f9335518c28d26429913258fc28f87 (patch)
treebc6aa880814da485343ae595c916de5ae52fcfa0 /Foundation.hs
parentd84b462a711ce95593ff05a7581e722562c3835a (diff)
downloadbar-53fcf55c02f9335518c28d26429913258fc28f87.tar
bar-53fcf55c02f9335518c28d26429913258fc28f87.tar.gz
bar-53fcf55c02f9335518c28d26429913258fc28f87.tar.bz2
bar-53fcf55c02f9335518c28d26429913258fc28f87.tar.xz
bar-53fcf55c02f9335518c28d26429913258fc28f87.zip
Extract appRoot from http headers
Diffstat (limited to 'Foundation.hs')
-rw-r--r--Foundation.hs17
1 files changed, 10 insertions, 7 deletions
diff --git a/Foundation.hs b/Foundation.hs
index 85512a3..d192c08 100644
--- a/Foundation.hs
+++ b/Foundation.hs
@@ -1,12 +1,20 @@
1module Foundation where 1module Foundation where
2 2
3import Import.NoFoundation 3import Import.NoFoundation hiding (requestHeaders)
4import Database.Persist.Sql (ConnectionPool, runSqlPool) 4import Database.Persist.Sql (ConnectionPool, runSqlPool)
5import Text.Hamlet (hamletFile) 5import Text.Hamlet (hamletFile)
6 6
7import Yesod.Core.Types (Logger) 7import Yesod.Core.Types (Logger)
8import qualified Yesod.Core.Unsafe as Unsafe 8import qualified Yesod.Core.Unsafe as Unsafe
9 9
10import qualified Data.Text.Encoding as TE
11import qualified Data.Text.Encoding.Error as TEE
12
13import Data.Map.Lazy (Map)
14import qualified Data.Map.Lazy as Map
15
16import Network.Wai (requestHeaders)
17
10-- | The foundation datatype for your application. This can be a good place to 18-- | The foundation datatype for your application. This can be a good place to
11-- keep settings and values requiring initialization before your application 19-- keep settings and values requiring initialization before your application
12-- starts running, such as database connections. Every handler will have 20-- starts running, such as database connections. Every handler will have
@@ -44,12 +52,7 @@ type Form x = Html -> MForm (HandlerT App IO) (FormResult x, Widget)
44-- Please see the documentation for the Yesod typeclass. There are a number 52-- Please see the documentation for the Yesod typeclass. There are a number
45-- of settings which can be configured by overriding methods here. 53-- of settings which can be configured by overriding methods here.
46instance Yesod App where 54instance Yesod App where
47 -- Controls the base of generated URLs. For more information on modifying, 55 approot = ApprootRequest $ \_ req -> maybe "" (TE.decodeUtf8With TEE.lenientDecode) $ Map.lookup "AppRoot" (Map.fromList $ requestHeaders req)
48 -- see: https://github.com/yesodweb/yesod/wiki/Overriding-approot
49 approot = ApprootRequest $ \app req ->
50 case appRoot $ appSettings app of
51 Nothing -> getApprootText guessApproot app req
52 Just root -> root
53 56
54 -- Store session data on the client in encrypted cookies, 57 -- Store session data on the client in encrypted cookies,
55 -- default session idle timeout is 120 minutes 58 -- default session idle timeout is 120 minutes