aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2021-07-23 22:17:34 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2021-07-23 23:14:09 +0100
commit5f4a3f8526df1cffd4cf39db20a9e601ced512bb (patch)
treec07e18926696067a96df2d51e5598d169197339a
parent3086d98cdc9232e220eba202a7d903b43cc6a444 (diff)
downloadnumberdisplay-5f4a3f8526df1cffd4cf39db20a9e601ced512bb.tar.gz
numberdisplay-5f4a3f8526df1cffd4cf39db20a9e601ced512bb.tar.bz2
numberdisplay-5f4a3f8526df1cffd4cf39db20a9e601ced512bb.zip
(Server)+basic error handling and an index route
-rw-r--r--Server/Main.hs32
-rw-r--r--Server/pages/error.html26
2 files changed, 58 insertions, 0 deletions
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 @@
+<!doctype html>
+<html class='no-js' lang=''>
+ <head>
+ <meta charset='utf-8'>
+ <meta http-equiv='x-ua-compatible' content='ie=edge'>
+ <title>NumberDisplay - Error</title>
+ <meta name='description' content='Error page for NumberDisplay program'>
+ <meta name='author' content='Aryadev Chavali'/>
+ <meta name='viewport' content='width=device-width, initial-scale=1'>
+
+ <link rel='apple-touch-icon' href='/apple-touch-icon.png'>
+ <link rel='shortcut icon' href='/favicon.ico'/>
+ <!-- Place favicon.ico in the root directory -->
+
+ </head>
+ <body>
+ <!--[if lt IE 8]>
+ <p class='browserupgrade'>
+ You are using an <strong>outdated</strong> browser. Please
+ <a href='http://browsehappy.com/'>upgrade your browser</a> to improve
+ your experience.
+ </p>
+ <![endif]-->
+ <p>Error... don't know what happened</p>
+ </body>
+</html>