From 53fcf55c02f9335518c28d26429913258fc28f87 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 14 Mar 2017 01:19:36 +0100 Subject: Extract appRoot from http headers --- Foundation.hs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'Foundation.hs') diff --git a/Foundation.hs b/Foundation.hs index 85512a3..d192c08 100644 --- a/Foundation.hs +++ b/Foundation.hs @@ -1,12 +1,20 @@ module Foundation where -import Import.NoFoundation +import Import.NoFoundation hiding (requestHeaders) import Database.Persist.Sql (ConnectionPool, runSqlPool) import Text.Hamlet (hamletFile) import Yesod.Core.Types (Logger) import qualified Yesod.Core.Unsafe as Unsafe +import qualified Data.Text.Encoding as TE +import qualified Data.Text.Encoding.Error as TEE + +import Data.Map.Lazy (Map) +import qualified Data.Map.Lazy as Map + +import Network.Wai (requestHeaders) + -- | The foundation datatype for your application. This can be a good place to -- keep settings and values requiring initialization before your application -- 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) -- Please see the documentation for the Yesod typeclass. There are a number -- of settings which can be configured by overriding methods here. instance Yesod App where - -- Controls the base of generated URLs. For more information on modifying, - -- see: https://github.com/yesodweb/yesod/wiki/Overriding-approot - approot = ApprootRequest $ \app req -> - case appRoot $ appSettings app of - Nothing -> getApprootText guessApproot app req - Just root -> root + approot = ApprootRequest $ \_ req -> maybe "" (TE.decodeUtf8With TEE.lenientDecode) $ Map.lookup "AppRoot" (Map.fromList $ requestHeaders req) -- Store session data on the client in encrypted cookies, -- default session idle timeout is 120 minutes -- cgit v1.2.3