on master help sign in
More backend refactors
commit3e10e05550b97eaf6e5001bdbfd6c6880d2b922f authorRyan Trinkle <ryan.trinkle@gmail.com> dateTue 10 Jul 2018, 18:27 (8 years ago) parent5dfd178
1 file changed+28−19
lib/backend/src/Obelisk/Backend.hs+28−19
lib/backend/src/Obelisk/Backend.hs+28−19
@@ -31,7 +31,7 @@ import Obelisk.Route
3131import Obelisk.Route.Frontend
3232import Reflex.Dom
3333import System.IO (hSetBuffering, stdout, stderr, BufferMode (..))
34−import Snap (MonadSnap, httpServe, defaultConfig, commandLineConfig, getsRequest, rqPathInfo, rqQueryString, writeText, writeBS)
34+import Snap (Snap, MonadSnap, httpServe, defaultConfig, commandLineConfig, getsRequest, rqPathInfo, rqQueryString, writeText, writeBS)
3535import Snap.Internal.Http.Server.Config (Config (accessLog, errorLog), ConfigLog (ConfigIoLog))
3636
3737--TODO: Add a link to a large explanation of the idea of using 'def'
@@ -78,28 +78,37 @@ backend cfg = do
7878 hSetBuffering stdout LineBuffering
7979 hSetBuffering stderr LineBuffering
8080
81− -- Get the web server configuration from the command line
82− cmdLineConf <- commandLineConfig defaultConfig
83− let httpConf = cmdLineConf
84− { accessLog = Just $ ConfigIoLog BSC8.putStrLn
85− , errorLog = Just $ ConfigIoLog BSC8.putStrLn
86− }
87− -- Start the web server
88− httpServe httpConf $ do
89− let staticAssets = StaticAssets
90− { _staticAssets_processed = "static.jsexe.assets"
91− , _staticAssets_unprocessed = "static.jsexe"
92− }
93− frontendApp = GhcjsApp
94− { _ghcjsApp_compiled = StaticAssets
95− { _staticAssets_processed = "frontend.jsexe.assets"
96− , _staticAssets_unprocessed = "frontend.jsexe"
97− }
81+ runSnapWithCommandLineArgs $ do
82+ let frontendApp = GhcjsApp
83+ { _ghcjsApp_compiled = defaultFrontendGhcjsAssets
9884 , _ghcjsApp_value = _backendConfig_frontend cfg
9985 }
10086 getRequestRoute >>= \case
10187 Left e -> writeText e
102− Right r -> serveObeliskRoute staticAssets frontendApp r
88+ Right r -> serveObeliskRoute defaultStaticAssets frontendApp r
89+
90+defaultStaticAssets :: StaticAssets
91+defaultStaticAssets = StaticAssets
92+ { _staticAssets_processed = "static.jsexe.assets"
93+ , _staticAssets_unprocessed = "static.jsexe"
94+ }
95+
96+defaultFrontendGhcjsAssets :: StaticAssets
97+defaultFrontendGhcjsAssets = StaticAssets
98+ { _staticAssets_processed = "frontend.jsexe.assets"
99+ , _staticAssets_unprocessed = "frontend.jsexe"
100+ }
101+
102+runSnapWithCommandLineArgs :: Snap () -> IO ()
103+runSnapWithCommandLineArgs a = do
104+ -- Get the web server configuration from the command line
105+ cmdLineConf <- commandLineConfig defaultConfig
106+ let httpConf = cmdLineConf
107+ { accessLog = Just $ ConfigIoLog BSC8.putStrLn
108+ , errorLog = Just $ ConfigIoLog BSC8.putStrLn
109+ }
110+ -- Start the web server
111+ httpServe httpConf a
103112
104113checkGetRequestRoute :: (MonadSnap m, Monad check, MonadError Text parse) => Encoder check parse route PageName -> check (m (parse route))
105114checkGetRequestRoute routeEncoder = do