~alcinnz/Hearth

a5f3016db36f3af4201a8b26ef9c32751ca95277 — Adrian Cochrane 11 months ago a359f85
Implement basic infrastructure for Hearth!
4 files changed, 21 insertions(+), 10 deletions(-)

M Hearth.cabal
M app/Main.hs
D src-lib/MyLib.hs
A tpl/index.html
M Hearth.cabal => Hearth.cabal +6 -3
@@ 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

M app/Main.hs => app/Main.hs +15 -3
@@ 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!"

D src-lib/MyLib.hs => src-lib/MyLib.hs +0 -4
@@ 1,4 0,0 @@
module MyLib (someFunc) where

someFunc :: IO ()
someFunc = putStrLn "someFunc"

A tpl/index.html => tpl/index.html +0 -0