11{-# LANGUAGE CPP #-}
22{-# LANGUAGE NoImplicitPrelude #-}
33module HTTP (
4- withServer
5- , socketName
6- , newSocket
7- , socketAddr
4+ AppConfig (.. )
5+ , withServer
86
97#ifdef TEST
108, app
@@ -25,8 +23,6 @@ import Network.Socket
2523
2624import Util
2725import qualified Trigger
28- import Config (Config )
29- import qualified Config
3026import qualified Config.DeepSeek as Config
3127import qualified DeepSeek
3228import GHC.Diagnostic
@@ -35,14 +31,21 @@ import HTTP.Util
3531import Sensei.API (QuickFixRequest (.. ), DeepFixRequest (.. ))
3632import qualified Sensei.API as API
3733
34+ data AppConfig = AppConfig {
35+ putStrLn :: String -> IO ()
36+ , deepSeek :: Maybe Config. DeepSeek
37+ , dir :: FilePath
38+ , getLastResult :: IO (Trigger. Result , String , [Diagnostic ])
39+ }
40+
3841socketAddr :: FilePath -> SockAddr
3942socketAddr = SockAddrUnix . socketName
4043
4144withSocket :: (Socket -> IO a ) -> IO a
4245withSocket = bracket newSocket close
4346
44- withServer :: ( String -> IO () ) -> Config -> FilePath -> IO ( Trigger. Result , String , [ Diagnostic ]) -> IO a -> IO a
45- withServer putStrLn config dir = withApplication dir . app putStrLn config dir
47+ withServer :: AppConfig -> IO a -> IO a
48+ withServer config = withApplication config . dir $ app config
4649
4750withApplication :: FilePath -> Application -> IO a -> IO a
4851withApplication dir application action = do
@@ -65,8 +68,8 @@ withThread asyncAction action = do
6568 takeMVar mvar
6669 return r
6770
68- app :: ( String -> IO () ) -> Config -> FilePath -> IO ( Trigger. Result , String , [ Diagnostic ]) -> Application
69- app putStrLn config dir getLastResult request respond = case pathInfo request of
71+ app :: AppConfig -> Application
72+ app config@ AppConfig { putStrLn , dir, getLastResult } request respond = case pathInfo request of
7073
7174 [] -> requireMethod " GET" $ do
7275 getLastResult >>= textPlain
0 commit comments