aboutsummaryrefslogtreecommitdiff
path: root/Server/Main.hs
blob: 8954d6d797b380a4d4b1eba2038c0b6886aaee2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{-# LANGUAGE OverloadedStrings #-}
module Main where

import Data.List
import Data.ByteString.Lazy (fromStrict)
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 =
  responseFile status200
  [("Content-Type", "text/html;charset=UTF-8")]
  "pages/index.html"
  Nothing

  responseLBS status200
  [("Content-Type", "text/plain")]
  "Hello, world!"

errorResponse :: Response
errorResponse =
  responseFile status200
  [("Content-Type", "text/html;charset=UTF-8")]
  "pages/error.html"
  Nothing

main :: IO ()
main = do
  putStrLn $ "http://localhost:8080/"
  run 8080 app