Skip to content

Commit

Permalink
api: Rename to EmaWebSocketOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
srid committed Dec 11, 2023
1 parent 870f664 commit a533a63
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions ema-examples/src/Ema/Example/Ex06_Markdown.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Ema
import Ema.CLI qualified as CLI
import Ema.Route.Generic.TH
import Ema.Route.Lib.Extra.PandocRoute qualified as Pandoc
import Ema.Server (EmaServerOptions (..))
import Ema.Server (EmaWebSocketOptions (..))
import Ema.Server.WebSocket.Options (EmaWsHandler (..), wsClientJS)
import Network.WebSockets qualified as WS
import Optics.Core ((%))
Expand Down Expand Up @@ -127,8 +127,8 @@ runWithFollow input = do
let cfg = SiteConfig cli followServerOptions
void $ snd <$> runSiteWith @Route cfg input

followServerOptions :: EmaServerOptions Route
followServerOptions = EmaServerOptions wsClientJS followServerHandler
followServerOptions :: EmaWebSocketOptions Route
followServerOptions = EmaWebSocketOptions wsClientJS followServerHandler

followServerHandler :: EmaWsHandler Route
followServerHandler = EmaWsHandler handle
Expand Down
2 changes: 1 addition & 1 deletion ema/src/Ema/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import System.Directory (getCurrentDirectory)

data SiteConfig r = SiteConfig
{ siteConfigCli :: CLI.Cli
, siteConfigServerOpts :: Server.EmaServerOptions r
, siteConfigServerOpts :: Server.EmaWebSocketOptions r
}

instance Default (SiteConfig r) where
Expand Down
10 changes: 5 additions & 5 deletions ema/src/Ema/Server.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Ema.Server (
EmaServerOptions (..),
EmaWebSocketOptions (..),
runServerWithWebSocketHotReload,
) where

Expand All @@ -9,7 +9,7 @@ import Ema.CLI (Host (unHost))
import Ema.Route.Class (IsRoute (RouteModel))
import Ema.Server.HTTP (httpApp)
import Ema.Server.WebSocket (wsApp)
import Ema.Server.WebSocket.Options (EmaServerOptions (..))
import Ema.Server.WebSocket.Options (EmaWebSocketOptions (..))
import Ema.Site (EmaStaticSite)
import Network.Wai qualified as Wai
import Network.Wai.Handler.Warp (Port)
Expand All @@ -29,7 +29,7 @@ runServerWithWebSocketHotReload ::
, IsRoute r
, EmaStaticSite r
) =>
EmaServerOptions r ->
EmaWebSocketOptions r ->
Host ->
Maybe Port ->
LVar (RouteModel r) ->
Expand All @@ -43,8 +43,8 @@ runServerWithWebSocketHotReload opts host mport model = do
app =
WaiWs.websocketsOr
WS.defaultConnectionOptions
(wsApp @r logger model $ emaServerWsHandler opts)
(httpApp @r logger model $ emaServerShim opts)
(wsApp @r logger model $ emaWebSocketServerHandler opts)
(httpApp @r logger model $ emaWebSocketClientShim opts)
banner port = do
logInfoNS "ema" "==============================================="
logInfoNS "ema" $ "Ema live server RUNNING: http://" <> unHost host <> ":" <> show port
Expand Down
10 changes: 5 additions & 5 deletions ema/src/Ema/Server/WebSocket/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ instance Default (EmaWsHandler r) where
where
log lvl (t :: Text) = logWithoutLoc "ema.ws" lvl t

data EmaServerOptions r = EmaServerOptions
{ emaServerShim :: LByteString
, emaServerWsHandler :: EmaWsHandler r
data EmaWebSocketOptions r = EmaWebSocketOptions
{ emaWebSocketClientShim :: LByteString
, emaWebSocketServerHandler :: EmaWsHandler r
}

instance Default (EmaServerOptions r) where
instance Default (EmaWebSocketOptions r) where
def =
EmaServerOptions wsClientJS def
EmaWebSocketOptions wsClientJS def

-- Browser-side JavaScript code for interacting with the Haskell server
wsClientJS :: LByteString
Expand Down

0 comments on commit a533a63

Please sign in to comment.