From 5f4a3f8526df1cffd4cf39db20a9e601ced512bb Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Fri, 23 Jul 2021 22:17:34 +0100 Subject: (Server)+basic error handling and an index route --- Server/Main.hs | 32 ++++++++++++++++++++++++++++++++ Server/pages/error.html | 26 ++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 Server/Main.hs create mode 100644 Server/pages/error.html diff --git a/Server/Main.hs b/Server/Main.hs new file mode 100644 index 0000000..bed3de5 --- /dev/null +++ b/Server/Main.hs @@ -0,0 +1,32 @@ +{-# LANGUAGE OverloadedStrings #-} +module Main where + +import Data.List +import Text.Printf +import Network.Wai +import Network.HTTP.Types +import Network.Wai.Handler.Warp (run) + +app :: Application +app request respond = respond $ + case rawPathInfo request of + "/" -> index + _ -> errorResponse + +index :: Response +index = + responseLBS status200 + [("Content-Type", "text/plain")] + "Hello, world!" + +errorResponse :: Response +errorResponse = + responseFile status200 + [("Content-Type", "text/plain")] + "pages/error.html" + Nothing + +main :: IO () +main = do + putStrLn $ "http://localhost:8080/" + run 8080 app diff --git a/Server/pages/error.html b/Server/pages/error.html new file mode 100644 index 0000000..c9cd2bc --- /dev/null +++ b/Server/pages/error.html @@ -0,0 +1,26 @@ + + + + + + NumberDisplay - Error + + + + + + + + + + + +

Error... don't know what happened

+ + -- cgit v1.2.3-13-gbd6f