Basic navigation and styles

This commit is contained in:
2024-02-18 18:16:09 -06:00
parent d8f3bc3c70
commit c63d28e779
10 changed files with 114 additions and 34 deletions

View File

@ -3,8 +3,10 @@ module Core.HTTP where
import qualified Core.Configuration as Conf
import qualified Core.Handlers as Handle
import Network.Wai.Middleware.RequestLogger (logStdoutDev)
import Network.Wai.Handler.Warp (Port, run)
import Network.Wai.Middleware.RequestLogger (logStdoutDev)
import Network.Wai.Middleware.Static
import Web.Twain
-- Get the port to listen on from the ENV and start the webserver
@ -14,9 +16,11 @@ main = do
run (read port :: Int) $
foldr ($) (notFound Handle.missing) app
-- These Middlewares are always executed before any routes are reached
-- These Middlewares are executed before any routes are reached
preProcessors :: [Middleware]
preProcessors = [logStdoutDev]
preProcessors = [ logStdoutDev
, staticPolicy $ noDots >-> addBase "data/assets/public"
]
-- The application's routes expressed as a list of WAI Middlewares
routes :: [Middleware]

View File

@ -2,15 +2,18 @@ module Core.Handlers where
import qualified Core.Configuration as Conf
import qualified Core.Rendering as R
import qualified Templates.Base as T
import Fragments.Base
import Fragments.NotFound
import Control.Monad.IO.Class (liftIO)
import Control.Monad.IO.Class (liftIO)
import Lucid (Html)
import Web.Twain
index :: ResponderM a
index = liftIO Conf.appTitle >>= (\title ->
send $ html $ R.twain $
T.baseDoc title T.baseNav)
sendLucidFragment
$ baseDoc title baseNav
<> baseHome)
testRoute :: ResponderM a
testRoute = do
@ -18,4 +21,7 @@ testRoute = do
send $ status status202 $ html $ "Testing echo parameter: " <> testParam
missing :: ResponderM a
missing = send $ html "404 NOT FOUND"
missing = sendLucidFragment pageNotFound
sendLucidFragment :: Html () -> ResponderM a
sendLucidFragment x = send $ html $ R.lucidToTwain x

View File

@ -3,5 +3,5 @@ module Core.Rendering where
import Lucid
import Data.ByteString.Lazy (ByteString)
twain :: Html () -> ByteString
twain = renderBS
lucidToTwain :: Html () -> ByteString
lucidToTwain = renderBS