blob: 0a00f54d680d510b7c7883340d21e98d9dd5ebc0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
|