-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
48efb13
commit fd05a4d
Showing
5 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
|
@@ -2,3 +2,5 @@ dist | ||
*.o | *.o | ||
*.hi | *.hi | ||
report.html | report.html | ||
example/Main | |||
example/Routes.hs |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,29 @@ | |||
{-# LANGUAGE OverloadedStrings #-} -- Whatever, it's just an example | |||
|
|||
module Application where | |||
|
|||
import Network.Wai | |||
import Network.HTTP.Types (ok200, notFound404) | |||
|
|||
import Data.Text (Text) | |||
import qualified Data.Text as T | |||
import qualified Data.Text.Encoding as T | |||
import qualified Data.ByteString.Lazy as LZ | |||
|
|||
import Data.Monoid (mappend) | |||
|
|||
textToUTF8 txt = LZ.fromChunks [T.encodeUtf8 txt] | |||
|
|||
showUTF8 :: (Show a) => a -> LZ.ByteString | |||
showUTF8 = textToUTF8 . T.pack . show | |||
|
|||
home _ = return $ responseLBS ok200 [("Content-Type", "text/plain")] "Hello World" | |||
|
|||
test val _ = return $ responseLBS ok200 [("Content-Type", "text/plain")] (textToUTF8 val) | |||
|
|||
on404 _ = return $ responseLBS notFound404 [("Content-Type", "text/plain")] "Not Found" | |||
|
|||
test2 :: Integer -> Application | |||
test2 val _ = return $ responseLBS ok200 [("Content-Type", "text/plain")] (showUTF8 val) | |||
|
|||
test3 val env = return $ responseLBS ok200 [("Content-Type", "text/plain")] (textToUTF8 val `mappend` "\n\n" `mappend` showUTF8 (pathInfo env)) |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,13 @@ | |||
module Main where | |||
|
|||
import Network.Wai | |||
import Network.Wai.Handler.Warp (run) | |||
import Network.Wai.Middleware.RequestLogger (logStdoutDev) | |||
|
|||
import Network.Wai.Dispatch | |||
import Application | |||
import Routes | |||
|
|||
main = do | |||
putStrLn "Running..." | |||
run 3000 (logStdoutDev $ dispatch on404 routes) |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
Main: Main.hs Application.hs Routes.hs | |||
ghc $^ | |||
|
|||
Routes.hs: routes | |||
../dist/build/routeGenerator/routeGenerator $^ Application > $@ |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
GET / => home | |||
GET /test/: => test | |||
GET /test2/: => test2 | |||
GET /test3/:/* => test3 |