@@ -1,14 +1,17 @@
11{-# LANGUAGE OverloadedStrings #-}
22module Obelisk.Backend
33 ( backend
4− , BackendConfig
4+ , BackendConfig (..)
55 -- * Re-exports
66 , Default (def)
77 ) where
88
9+import Control.Lens
910import qualified Data.ByteString.Char8 as BSC8
1011import Data.Default (Default (..))
1112import Obelisk.Asset.Serve.Snap (serveAssets)
13+import Obelisk.Snap
14+import Reflex.Dom
1215import System.IO (hSetBuffering, stderr, BufferMode (..))
1316import Snap (httpServe, defaultConfig, commandLineConfig, route)
1417import Snap.Internal.Http.Server.Config (Config (accessLog, errorLog), ConfigLog (ConfigIoLog))
@@ -17,25 +20,30 @@ import Snap.Internal.Http.Server.Config (Config (accessLog, errorLog), ConfigLog
1720-- | Configure the operation of the Obelisk backend. For reasonable defaults,
1821-- use 'def'.
1922data BackendConfig = BackendConfig
23+ { _backendConfig_head :: StaticWidget () ()
24+ }
2025
2126instance Default BackendConfig where
22− def = BackendConfig
27+ def = BackendConfig (return ())
2328
2429-- | Start an Obelisk backend
2530backend :: BackendConfig -> IO ()
26−backend _ = do
31+backend cfg = do
2732 -- Make output more legible by decreasing the likelihood of output from
2833 -- multiple threads being interleaved
2934 hSetBuffering stderr LineBuffering
3035
3136 -- Get the web server configuration from the command line
3237 cmdLineConf <- commandLineConfig defaultConfig
38+ headHtml <- fmap snd $ renderStatic $ _backendConfig_head cfg
3339 let httpConf = cmdLineConf
3440 { accessLog = Just $ ConfigIoLog BSC8.putStrLn
3541 , errorLog = Just $ ConfigIoLog BSC8.putStrLn
3642 }
43+ appCfg = def & appConfig_initialHead .~ headHtml
3744 -- Start the web server
3845 httpServe httpConf $ route
39− [ ("", serveAssets "frontend.jsexe.assets" "frontend.jsexe") --TODO: Can we prevent naming conflicts between frontend.jsexe and static?
46+ [ ("", serveApp "" appCfg)
47+ , ("", serveAssets "frontend.jsexe.assets" "frontend.jsexe") --TODO: Can we prevent naming conflicts between frontend.jsexe and static?
4048 , ("", serveAssets "static.assets" "static")
4149 ]