M app/Main.hs => app/Main.hs +16 -1
@@ 1,5 1,20 @@
+{-# LANGUAGE OverloadedStrings #-}
module Main where
+import Network.Wai.Handler.Warp
+import Network.Wai
+import Network.HTTP.Types
+
+import Text.HTML.Form.WebApp
+import Data.Text.Lazy.Encoding (encodeUtf8)
+import Data.Text.Lazy (fromStrict)
+
main :: IO ()
main = do
- putStrLn "Hello, Haskell!"
+ runEnv 2018 servePage
+
+servePage req respond = do
+ ret <- renderPage Form (pathInfo req) (queryString req)
+ case ret of
+ Just txt -> respond $ responseLBS status200 [] $ encodeUtf8 $ fromStrict txt
+ Nothing -> respond $ responseLBS status404 [] "Unknown input or operation!"
M bureaucromancy.cabal => bureaucromancy.cabal +2 -2
@@ 62,7 62,7 @@ library
import: warnings
-- Modules exported by the library.
- exposed-modules: Network.HTTP.Form, Network.HTTP.Form.WebApp
+ exposed-modules: Text.HTML.Form, Text.HTML.Form.WebApp
-- Modules included in this library but not exported.
-- other-modules:
@@ 95,7 95,7 @@ executable bureaucromancy
-- Other library packages from which modules are imported.
build-depends:
base ^>=4.16.4.0,
- bureaucromancy, warp
+ bureaucromancy, warp, wai, http-types, text
-- Directories containing source files.
hs-source-dirs: app
D src/Network/HTTP/Form/WebApp.hs => src/Network/HTTP/Form/WebApp.hs +0 -9
@@ 1,9 0,0 @@
-{-# LANGUAGE OverloadedStrings #-}
-module Network.HTTP.Form.WebApp (renderPage) where
-
-import Data.ByteString as BS
-import Data.Text as Txt
-import Network.HTTP.Form (Form(..))
-
-renderPage :: Form -> [Text] -> [(ByteString, Maybe ByteString)] -> IO Text
-renderPage _ _ _ = return ""
R src/Network/HTTP/Form.hs => src/Text/HTML/Form.hs +1 -1
@@ 1,3 1,3 @@
-module Network.HTTP.Form (Form(..)) where
+module Text.HTML.Form (Form(..)) where
data Form = Form
A src/Text/HTML/Form/WebApp.hs => src/Text/HTML/Form/WebApp.hs +9 -0
@@ 0,0 1,9 @@
+{-# LANGUAGE OverloadedStrings #-}
+module Text.HTML.Form.WebApp (renderPage, Form(..)) where
+
+import Data.ByteString as BS
+import Data.Text as Txt
+import Text.HTML.Form (Form(..))
+
+renderPage :: Form -> [Text] -> [(ByteString, Maybe ByteString)] -> IO (Maybe Text)
+renderPage _ _ _ = return $ Just ""