@@ -0,0 +1,37 @@
1+module Obelisk.Backend
2+ ( backend
3+ , BackendConfig
4+ -- * Re-exports
5+ , Default (def)
6+ ) where
7+
8+import qualified Data.ByteString.Char8 as BSC8
9+import Data.Default (Default (..))
10+import Obelisk.Asset.Serve (serveAssets)
11+import System.IO (hSetBuffering, stderr, BufferMode (..))
12+import Snap (httpServe, defaultConfig, commandLineConfig)
13+import Snap.Internal.Http.Server.Config (Config (accessLog, errorLog), ConfigLog (ConfigIoLog))
14+
15+--TODO: Add a link to a large explanation of the idea of using 'def'
16+-- | Configure the operation of the Obelisk backend. For reasonable defaults,
17+-- use 'def'.
18+data BackendConfig = BackendConfig
19+
20+instance Default BackendConfig where
21+ def = BackendConfig
22+
23+-- | Start an Obelisk backend
24+backend :: BackendConfig -> IO ()
25+backend _ = do
26+ -- Make output more legible by decreasing the likelihood of output from
27+ -- multiple threads being interleaved
28+ hSetBuffering stderr LineBuffering
29+
30+ -- Get the web server configuration from the command line
31+ cmdLineConf <- commandLineConfig defaultConfig
32+ let httpConf = cmdLineConf
33+ { accessLog = Just $ ConfigIoLog BSC8.putStrLn
34+ , errorLog = Just $ ConfigIoLog BSC8.putStrLn
35+ }
36+ -- Start the web server
37+ httpServe httpConf $ serveAssets "static.assets" "static"