From a5f3016db36f3af4201a8b26ef9c32751ca95277 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Wed, 10 Jan 2024 15:13:53 +1300 Subject: [PATCH] Implement basic infrastructure for Hearth! --- Hearth.cabal | 9 ++++++--- app/Main.hs | 18 +++++++++++++++--- src-lib/MyLib.hs | 4 ---- tpl/index.html | 0 4 files changed, 21 insertions(+), 10 deletions(-) delete mode 100644 src-lib/MyLib.hs create mode 100644 tpl/index.html diff --git a/Hearth.cabal b/Hearth.cabal index 495ec00..5f2e6ee 100644 --- a/Hearth.cabal +++ b/Hearth.cabal @@ -62,7 +62,7 @@ library import: warnings -- Modules exported by the library. - exposed-modules: MyLib + exposed-modules: Hearth -- Modules included in this library but not exported. -- other-modules: @@ -71,7 +71,8 @@ library -- other-extensions: -- Other library packages from which modules are imported. - build-depends: base ^>=4.17.0.0 + build-depends: base ^>=4.17.0.0, ginger>0.10 && <1, bytestring, text, + file-embed, mtl, filepath -- Directories containing source files. hs-source-dirs: src-lib @@ -95,7 +96,9 @@ executable Hearth -- Other library packages from which modules are imported. build-depends: base ^>=4.17.0.0, - Hearth + Hearth, + warp >= 3.3.31 && < 3.4, wai >= 3.2.3 && < 3.3, + http-types >= 0.12.3 && < 0.13, text >= 2.0.1 && < 2.1 -- Directories containing source files. hs-source-dirs: app diff --git a/app/Main.hs b/app/Main.hs index 60d904e..2a3ef7e 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,8 +1,20 @@ +{-# LANGUAGE OverloadedStrings #-} module Main where -import qualified MyLib (someFunc) +import Network.Wai.Handler.Warp +import Network.Wai +import Network.HTTP.Types +import Data.Text.Lazy (fromStrict) +import Data.Text.Lazy.Encoding (encodeUtf8) + +import Hearth (renderPage) main :: IO () main = do - putStrLn "Hello, Haskell!" - MyLib.someFunc + runEnv 2019 servePage + +servePage :: Application +servePage req respond = case requestMethod req of + "GET" | Just resp <- renderPage (rawPathInfo req) (queryString req) -> + respond $ responseLBS status200 [] $ encodeUtf8 $ fromStrict resp + _ -> respond $ responseLBS status404 [] "Page not found!" diff --git a/src-lib/MyLib.hs b/src-lib/MyLib.hs deleted file mode 100644 index e657c44..0000000 --- a/src-lib/MyLib.hs +++ /dev/null @@ -1,4 +0,0 @@ -module MyLib (someFunc) where - -someFunc :: IO () -someFunc = putStrLn "someFunc" diff --git a/tpl/index.html b/tpl/index.html new file mode 100644 index 0000000..e69de29 -- 2.30.2