@@ -11,7 +11,6 @@ module Obelisk.Backend
1111 ( Backend (..)
1212 -- * Re-exports
1313 , Default (def)
14− , ComponentConfigs(..)
1514 , getPageName
1615 , getRouteWith
1716 , runSnapWithCommandLineArgs
@@ -20,7 +19,7 @@ module Obelisk.Backend
2019 , runBackend
2120 , staticRenderContentType
2221 , mkRouteToUrl
23− , getComponentConfigs
22+ , getPublicConfigs
2423 ) where
2524
2625import Prelude hiding (id, (.))
@@ -41,7 +40,6 @@ import Data.Text (Text)
4140import qualified Data.Text as T
4241import Data.Text.Encoding
4342import Obelisk.Asset.Serve.Snap (serveAsset)
44−import Obelisk.Configs
4543import qualified Obelisk.ExecutableConfig.Lookup as Lookup
4644import Obelisk.Frontend
4745import Obelisk.Route
@@ -55,14 +53,7 @@ import System.IO (BufferMode (..), hSetBuffering, stderr, stdout)
5553
5654data Backend backendRoute frontendRoute = Backend
5755 { _backend_routeEncoder :: Encoder (Either Text) Identity (R (Sum backendRoute (ObeliskRoute frontendRoute))) PageName
58− , _backend_run :: ((R backendRoute -> ConfigsT Snap ()) -> ConfigsT IO ()) -> ConfigsT IO ()
59− }
60−
61−-- | All the configs separated by which context they are accessible in. Common
62−-- and frontend configs are present in both.
63−data ComponentConfigs = ComponentConfigs
64− { _componentConfigs_backend :: Map Text ByteString
65− , _componentConfigs_frontend :: Map Text ByteString
56+ , _backend_run :: ((R backendRoute -> Snap ()) -> IO ()) -> IO ()
6657 }
6758
6859-- | The static assets provided must contain a compiled GHCJS app that corresponds exactly to the Frontend provided
@@ -187,17 +178,15 @@ runBackend :: Backend fullRoute frontendRoute -> Frontend (R frontendRoute) -> I
187178runBackend backend frontend = case checkEncoder $ _backend_routeEncoder backend of
188179 Left e -> fail $ "backend error:\n" <> T.unpack e
189180 Right validFullEncoder -> do
190− configs <- getComponentConfigs
191− runConfigsT (_componentConfigs_backend configs) $
192− _backend_run backend $ \serveRoute -> do
193− runSnapWithCommandLineArgs $ do
194− getRouteWith validFullEncoder >>= \case
195− Identity r -> case r of
196− InL backendRoute :=> Identity a ->
197− runConfigsT (_componentConfigs_backend configs) $
198− serveRoute $ backendRoute :/ a
199− InR obeliskRoute :=> Identity a ->
200− serveDefaultObeliskApp (mkRouteToUrl validFullEncoder) (serveStaticAssets defaultStaticAssets) frontend (_componentConfigs_frontend configs) $ obeliskRoute :/ a
181+ publicConfigs <- getPublicConfigs
182+ _backend_run backend $ \serveRoute -> do
183+ runSnapWithCommandLineArgs $ do
184+ getRouteWith validFullEncoder >>= \case
185+ Identity r -> case r of
186+ InL backendRoute :=> Identity a -> serveRoute $ backendRoute :/ a
187+ InR obeliskRoute :=> Identity a ->
188+ serveDefaultObeliskApp (mkRouteToUrl validFullEncoder) (serveStaticAssets defaultStaticAssets) frontend publicConfigs $
189+ obeliskRoute :/ a
201190
202191mkRouteToUrl :: Encoder Identity parse (R (Sum f (ObeliskRoute r))) PageName -> R r -> Text
203192mkRouteToUrl validFullEncoder =
@@ -220,13 +209,9 @@ renderGhcjsFrontend urlEnc route configs f = do
220209instance HasCookies Snap where
221210 askCookies = map (\c -> (cookieName c, cookieValue c)) <$> getsRequest rqCookies
222211
223−getComponentConfigs :: IO ComponentConfigs
224−getComponentConfigs = do
225− allConfigs <- Lookup.getConfigs
226− return $ ComponentConfigs
227− { _componentConfigs_backend =
228− allConfigs
229− , _componentConfigs_frontend =
230− Map.filterWithKey (\k _ -> isMemberOf k ["common", "frontend"]) allConfigs
231− }
232− where isMemberOf k dirs = or $ map (`T.isPrefixOf` k) dirs
212+-- | Get configs from the canonical "public" locations (i.e., locations that obelisk expects to make available
213+-- to frontend applications, and hence visible to end users).
214+getPublicConfigs :: IO (Map Text ByteString)
215+getPublicConfigs = Map.filterWithKey (\k _ -> isMemberOf k ["common", "frontend"]) <$> Lookup.getConfigs
216+ where
217+ isMemberOf k = any (`T.isPrefixOf` k)