From c4e5e3791485b5dcb08066ab81e0157d6e70c1d2 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Wed, 26 Nov 2025 05:48:07 -0500 Subject: Add jr web command with Servant skeleton Task-Id: t-1o2g8gugkr1.1 --- Omni/Jr/Web.hs | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Omni/Jr/Web.hs (limited to 'Omni/Jr') 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 -- cgit v1.2.3