diff options
| author | Ben Sima <ben@bensima.com> | 2025-11-26 05:48:07 -0500 |
|---|---|---|
| committer | Ben Sima <ben@bensima.com> | 2025-11-26 05:48:07 -0500 |
| commit | c4e5e3791485b5dcb08066ab81e0157d6e70c1d2 (patch) | |
| tree | e9a4a41f772c2df29d23ab79678a269958a230e0 /Omni/Jr | |
| parent | 01de0612b51b64077d10d05268e89f5e2b3b8001 (diff) | |
Add jr web command with Servant skeleton
Task-Id: t-1o2g8gugkr1.1
Diffstat (limited to 'Omni/Jr')
| -rw-r--r-- | Omni/Jr/Web.hs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/Omni/Jr/Web.hs b/Omni/Jr/Web.hs new file mode 100644 index 0000000..0a00f54 --- /dev/null +++ b/Omni/Jr/Web.hs @@ -0,0 +1,54 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE NoImplicitPrelude #-} + +-- : dep warp +-- : dep servant-server +-- : dep lucid +-- : dep servant-lucid +module Omni.Jr.Web + ( run, + defaultPort, + ) +where + +import Alpha +import qualified Lucid +import qualified Network.Wai.Handler.Warp as Warp +import Servant +import qualified Servant.HTML.Lucid as Lucid + +defaultPort :: Warp.Port +defaultPort = 8080 + +type API = Get '[Lucid.HTML] HomePage + +newtype HomePage = HomePage () + +instance Lucid.ToHtml HomePage where + toHtmlRaw = Lucid.toHtml + toHtml (HomePage ()) = + Lucid.doctypehtml_ <| do + Lucid.head_ <| do + Lucid.title_ "Jr Web UI" + Lucid.meta_ [Lucid.charset_ "utf-8"] + Lucid.meta_ + [ Lucid.name_ "viewport", + Lucid.content_ "width=device-width, initial-scale=1" + ] + Lucid.body_ <| do + Lucid.h1_ "Jr Web UI" + +api :: Proxy API +api = Proxy + +server :: Server API +server = pure (HomePage ()) + +app :: Application +app = serve api server + +run :: Warp.Port -> IO () +run port = do + putText <| "Starting Jr web server on port " <> tshow port + Warp.run port app |
