Permalink
Browse files

done.

  • Loading branch information...
ujihisa committed Dec 7, 2010
1 parent 3037ba6 commit 13771bce4cf575e27c89cc3b3c548eb393836194
Showing with 12 additions and 6 deletions.
  1. +12 −6 src/Main.hs
View
@@ -9,22 +9,28 @@ import Text.Templating.Heist.TemplateDirectory
import Glue
import Server
+import Data.ByteString.Char8 (pack, unpack)
+fibs :: [Integer]
+fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
+
+fibInString :: Int -> String
+fibInString n = "fib(" ++ show n ++ ") = " ++ show (fibs !! n)
main :: IO ()
main = do
td <- newTemplateDirectory' "templates" emptyTemplateState
quickServer $ templateHandler td defaultReloadHandler $ \ts ->
ifTop (writeBS "hello world") <|>
route [ ("foo", writeBS "bar")
- , ("echo/:echoparam", echoHandler)
+ , ("fib/:n", fibHandler)
] <|>
templateServe ts <|>
dir "static" (fileServe ".")
-echoHandler :: Snap ()
-echoHandler = do
- param <- getParam "echoparam"
- maybe (writeBS "must specify echo/param in URL")
- writeBS param
+fibHandler :: Snap ()
+fibHandler = do
+ param <- getParam "n"
+ maybe (writeBS "must specify fib/n in URL")
+ (writeBS . pack . fibInString . read . unpack) param

0 comments on commit 13771bc

Please sign in to comment.