diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2017-03-14 01:19:36 +0100 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2017-03-14 01:19:36 +0100 |
commit | 53fcf55c02f9335518c28d26429913258fc28f87 (patch) | |
tree | bc6aa880814da485343ae595c916de5ae52fcfa0 /Foundation.hs | |
parent | d84b462a711ce95593ff05a7581e722562c3835a (diff) | |
download | bar-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.hs | 17 |
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 @@ | |||
1 | module Foundation where | 1 | module Foundation where |
2 | 2 | ||
3 | import Import.NoFoundation | 3 | import Import.NoFoundation hiding (requestHeaders) |
4 | import Database.Persist.Sql (ConnectionPool, runSqlPool) | 4 | import Database.Persist.Sql (ConnectionPool, runSqlPool) |
5 | import Text.Hamlet (hamletFile) | 5 | import Text.Hamlet (hamletFile) |
6 | 6 | ||
7 | import Yesod.Core.Types (Logger) | 7 | import Yesod.Core.Types (Logger) |
8 | import qualified Yesod.Core.Unsafe as Unsafe | 8 | import qualified Yesod.Core.Unsafe as Unsafe |
9 | 9 | ||
10 | import qualified Data.Text.Encoding as TE | ||
11 | import qualified Data.Text.Encoding.Error as TEE | ||
12 | |||
13 | import Data.Map.Lazy (Map) | ||
14 | import qualified Data.Map.Lazy as Map | ||
15 | |||
16 | import 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. |
46 | instance Yesod App where | 54 | instance 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 |