Last active
December 19, 2015 09:29
-
-
Save amothic/5933808 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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