Created
July 4, 2016 14:18
-
-
Save deckool/73d1147956364fc167788c8d7854b81b to your computer and use it in GitHub Desktop.
small starter for maybe eventsource on snap framework
This file contains hidden or 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 #-} | |
module Main where | |
import Control.Applicative | |
import Snap.Core | |
import Snap.Util.FileServe | |
import Snap.Http.Server | |
import Control.Monad.IO.Class | |
import qualified Data.ByteString.Char8 as BS | |
main :: IO () | |
main = quickHttpServe site | |
site :: Snap () | |
site = do | |
a <- getRequest | |
liftIO $ print a | |
routes a | |
where | |
routes a = | |
ifTop (writeBS "hello world") <|> | |
route [ ("foo", writeBS $ BS.pack (show a)) | |
, ("echo/:echoparam", echoHandler) | |
] <|> | |
dir "static" (serveDirectory ".") | |
echoHandler :: Snap () | |
echoHandler = do | |
param <- getParam "echoparam" | |
maybe (writeBS "must specify echo/param in URL") | |
writeBS param |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment