on master help sign in
Add Obelisk.Backend.runBackend
commitab03bde5823279bfdd985eb9251a377342a12b4f authorRyan Trinkle <ryan.trinkle@gmail.com> dateMon 16 Jul 2018, 14:42 (8 years ago) parent00bdec8
2 files changed+13
lib/backend/src/Obelisk/Backend.hs+12 lib/run/src/Obelisk/Run.hs+1
lib/backend/src/Obelisk/Backend.hs+12
@@ -15,6 +15,7 @@ module Obelisk.Backend
1515 , runSnapWithCommandLineArgs
1616 , serveDefaultObeliskApp
1717 , prettifyOutput
18+ , runBackend
1819 ) where
1920
2021import Control.Monad.Except
@@ -163,3 +164,14 @@ blankLoader headHtml = el "html" $ do
163164 el "body" $ do
164165 --TODO: Hash the all.js path
165166 elAttr "script" ("language" =: "javascript" <> "src" =: "ghcjs/all.js" <> "defer" =: "defer") blank
167+
168+runBackend :: Backend fullRoute frontendRoute -> Frontend (R frontendRoute) -> IO ()
169+runBackend backend frontend = case checkEncoder $ _backend_routeEncoder backend of
170+ Left e -> fail $ "backend error:\n" <> T.unpack e
171+ Right validFullEncoder -> _backend_run backend $ \serveRoute -> do
172+ runSnapWithCommandLineArgs $ do
173+ getRouteWith validFullEncoder >>= \case
174+ Left e -> writeText e
175+ Right r -> case r of
176+ InL backendRoute :=> Identity a -> serveRoute $ backendRoute :/ a
177+ InR obeliskRoute :=> Identity a -> serveDefaultObeliskApp frontend $ obeliskRoute :/ a
lib/run/src/Obelisk/Run.hs+1
@@ -71,6 +71,7 @@ run
7171run port backend frontend = do
7272 prettifyOutput
7373 let handleBackendErr (e :: IOException) = hPutStrLn stderr $ "backend stopped; make a change to your code to reload - error " <> show e
74+ --TODO: Use Obelisk.Backend.runBackend; this will require separating the checking and running phases
7475 case checkEncoder $ _backend_routeEncoder backend of
7576 Left e -> hPutStrLn stderr $ "backend error:\n" <> T.unpack e
7677 Right validFullEncoder -> do