|
|
@@ -1,4 +1,45 @@ |
|
|
|
module Main where |
|
|
|
|
|
|
|
import Web.Scotty |
|
|
|
|
|
|
|
import Data.Monoid (mconcat) |
|
|
|
import Helpers |
|
|
|
import Network.HTTP.Types.Status |
|
|
|
import qualified Data.Text.Lazy as T |
|
|
|
import Network.Wai |
|
|
|
import Network.Wai.Middleware.RequestLogger |
|
|
|
import Network.Wai.Middleware.HttpAuth |
|
|
|
import qualified Data.ByteString as BS |
|
|
|
import qualified Data.ByteString.UTF8 as U8 |
|
|
|
|
|
|
|
|
|
|
|
main :: IO () |
|
|
|
main = putStrLn "Hello, Haskell!" |
|
|
|
main = scotty 3000 $ do |
|
|
|
middleware auth |
|
|
|
middleware logging |
|
|
|
get (fS "/foo") foo |
|
|
|
get (fS "/:word") word_pattern |
|
|
|
|
|
|
|
|
|
|
|
word_pattern :: ActionM () |
|
|
|
word_pattern = do |
|
|
|
beam <- param (fS "word") |
|
|
|
html $ mconcat [fS "<h1>Scotty, ", beam, fS " me up!</h1>"] |
|
|
|
|
|
|
|
|
|
|
|
foo :: ActionM () |
|
|
|
foo = do |
|
|
|
status ok200 |
|
|
|
text $ T.pack "Blah" |
|
|
|
return () |
|
|
|
|
|
|
|
|
|
|
|
logging :: Middleware |
|
|
|
logging = logStdout |
|
|
|
|
|
|
|
|
|
|
|
auth :: Middleware |
|
|
|
auth = basicAuth (\u p -> return $ |
|
|
|
u == U8.fromString "michael" && |
|
|
|
p == U8.fromString "mypass") |
|
|
|
(fS "My Realm") |