on master help sign in
Only remove configs from head in GHCJS / ob run
commit799cfb803cdede53deec696af677c05527dad7d7 authorKen Micklas <ken.micklas@obsidian.systems> dateMon 29 Apr 2019, 17:26 (7 years ago) parent4f496ad
2 files changed+21−3
lib/frontend/src/Obelisk/Frontend.hs+17−2 lib/run/src/Obelisk/Run.hs+4−1
lib/frontend/src/Obelisk/Frontend.hs+17−2
@@ -1,4 +1,5 @@
11{-# LANGUAGE ConstraintKinds #-}
2+{-# LANGUAGE CPP #-}
23{-# LANGUAGE FlexibleContexts #-}
34{-# LANGUAGE FlexibleInstances #-}
45{-# LANGUAGE LambdaCase #-}
@@ -14,7 +15,9 @@ module Obelisk.Frontend
1415 ( ObeliskWidget
1516 , Frontend (..)
1617 , runFrontend
18+ , runFrontendWithConfigs
1719 , renderFrontendHtml
20+ , removeHTMLConfigs
1821 , module Obelisk.Frontend.Cookie
1922 ) where
2023
@@ -31,6 +34,7 @@ import Control.Monad.Trans.Maybe (MaybeT(..), runMaybeT)
3134import Data.ByteString (ByteString)
3235import Data.Foldable (for_)
3336import Data.Functor.Sum
37+import Data.Map (Map)
3438import Data.Maybe (catMaybes)
3539import Data.Monoid ((<>))
3640import Data.Text (Text)
@@ -106,12 +110,23 @@ runFrontend
106110 -> Frontend (R route)
107111 -> JSM ()
108112runFrontend validFullEncoder frontend = do
113+ configs <- liftIO getFrontendConfigs
114+#ifdef ghcjs_HOST_OS
115+ removeHTMLConfigs
116+#endif
117+ runFrontendWithConfigs configs validFullEncoder frontend
118+
119+runFrontendWithConfigs
120+ :: forall backendRoute route
121+ . Map Text Text
122+ -> Encoder Identity Identity (R (Sum backendRoute (ObeliskRoute route))) PageName
123+ -> Frontend (R route)
124+ -> JSM ()
125+runFrontendWithConfigs configs validFullEncoder frontend = do
109126 let ve = validFullEncoder . hoistParse errorLeft (prismEncoder (rPrism $ _InR . _ObeliskRoute_App))
110127 errorLeft = \case
111128 Left _ -> error "runFrontend: Unexpected non-app ObeliskRoute reached the frontend. This shouldn't happen."
112129 Right x -> Identity x
113− configs <- liftIO getFrontendConfigs
114− removeHTMLConfigs
115130 runHydrationWidgetWithHeadAndBody (pure ()) $ \appendHead appendBody -> do
116131 rec switchover <- runRouteViewT ve switchover $ do
117132 (switchover'', fire) <- newTriggerEvent
lib/run/src/Obelisk/Run.hs+4−1
@@ -18,6 +18,7 @@ import Control.Category
1818import Control.Concurrent
1919import Control.Exception
2020import Control.Lens ((%~), (^?), _Just, _Right)
21+import Control.Monad.IO.Class
2122import qualified Data.Attoparsec.ByteString.Char8 as A
2223import Data.ByteString (ByteString)
2324import qualified Data.ByteString.Char8 as BSC
@@ -127,7 +128,9 @@ obeliskApp
127128 -> IO Application
128129obeliskApp opts frontend validFullEncoder uri backend = do
129130 let entryPoint = do
130− runFrontend validFullEncoder frontend
131+ configs <- liftIO getFrontendConfigs
132+ removeHTMLConfigs
133+ runFrontendWithConfigs configs validFullEncoder frontend
131134 syncPoint
132135 jsaddlePath <- URI.mkPathPiece "jsaddle"
133136 let jsaddleUri = BSLC.fromStrict $ URI.renderBs $ uri & uriPath %~ (<>[jsaddlePath])