init sampu

This commit is contained in:
2024-02-18 10:37:40 -06:00
commit 3e81ea8fec
9 changed files with 222 additions and 0 deletions

31
src/Core/HTTP.hs Normal file
View File

@ -0,0 +1,31 @@
module Core.HTTP where
import qualified Core.Handlers as Handle
import Network.Wai.Middleware.RequestLogger (logStdoutDev)
import Network.Wai.Handler.Warp (Port, run)
import Web.Twain
main :: IO ()
main = do
run appPort $
foldr ($) (notFound Handle.missing) app
-- Combine our Preprocessor Middlewares and Routes to create an App
app :: [Middleware]
app = preProcessors ++ routes
-- These Middleware are always executed before any routes are reached
preProcessors :: [Middleware]
preProcessors = [logStdoutDev]
-- The application's core routes expressed as a list of WAI middlewares
routes :: [Middleware]
routes =
[ get "/" Handle.index
, get "/echo/:testParam" Handle.testRoute
]
-- This will be replaced with getEnv located in Configuration
appPort :: Port
appPort = 3000

17
src/Core/Handlers.hs Normal file
View File

@ -0,0 +1,17 @@
module Core.Handlers where
import qualified Templates.Base as T
import Core.Rendering as R
import Web.Twain
index :: ResponderM a
index = send $ html $ R.twain T.baseNav
testRoute :: ResponderM a
testRoute = do
testParam <- param "testParam"
send $ status status202 $ html $ "Testing echo parameter: " <> testParam
missing :: ResponderM a
missing = send $ html "404 NOT FOUND"

7
src/Core/Rendering.hs Normal file
View File

@ -0,0 +1,7 @@
module Core.Rendering where
import Lucid
import Data.ByteString.Lazy (ByteString)
twain :: Html () -> ByteString
twain = renderBS

6
src/Main.hs Normal file
View File

@ -0,0 +1,6 @@
module Main where
import qualified Core.HTTP as Core
main :: IO ()
main = Core.main

13
src/Templates/Base.hs Normal file
View File

@ -0,0 +1,13 @@
module Templates.Base where
import Lucid
baseNav :: Html ()
baseNav = doctypehtml_ $ do
head_ $ do
title_ getBlogTitle
link_ [rel_ "stylesheet", type_ "text/css", href_ "style.css"]
body_ $ do
h1_ "This will be a nav eventually."
where
getBlogTitle = "unimplemented getEnv"