Skip to content

Instantly share code, notes, and snippets.

@amothic
Last active December 19, 2015 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amothic/5933808 to your computer and use it in GitHub Desktop.
Save amothic/5933808 to your computer and use it in GitHub Desktop.
{-# LANGUAGE OverloadedStrings #-}
import Network.Wai
import Network.HTTP.Types (status200, status404)
import Network.Wai.Handler.Warp (run)
application request = return $
routes $ pathInfo request
routes path = findRoute path routeSetting
findRoute path [] = notFound
findRoute path ((p,f):xs)
| path == p = f
| otherwise = findRoute path xs
routeSetting = [([], index),
(["hello"], hello),
(["welcome","world"],world)]
notFound =
responseLBS status404 [("Content-type", "text/html")] $ "404 - File Not Found"
index =
responseLBS status200 [("Content-type", "text/html")] $ "index page"
hello =
responseLBS status200 [("Content-type", "text/html")] $ "hello, my name is Tom"
world =
responseLBS status200 [("Content-type", "text/html")] $ "Welcome to Underground"
main = run 3000 application
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment