init sampu
This commit is contained in:
31
src/Core/HTTP.hs
Normal file
31
src/Core/HTTP.hs
Normal 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
17
src/Core/Handlers.hs
Normal 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
7
src/Core/Rendering.hs
Normal file
@ -0,0 +1,7 @@
|
||||
module Core.Rendering where
|
||||
|
||||
import Lucid
|
||||
import Data.ByteString.Lazy (ByteString)
|
||||
|
||||
twain :: Html () -> ByteString
|
||||
twain = renderBS
|
Reference in New Issue
Block a user