You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

46 lines
931 B

  1. module Main where
  2. import Web.Scotty
  3. import Data.Monoid (mconcat)
  4. import Helpers
  5. import Network.HTTP.Types.Status
  6. import qualified Data.Text.Lazy as T
  7. import Network.Wai
  8. import Network.Wai.Middleware.RequestLogger
  9. import Network.Wai.Middleware.HttpAuth
  10. import qualified Data.ByteString as BS
  11. import qualified Data.ByteString.UTF8 as U8
  12. main :: IO ()
  13. main = scotty 3000 $ do
  14. middleware auth
  15. middleware logging
  16. get (fS "/foo") foo
  17. get (fS "/:word") word_pattern
  18. word_pattern :: ActionM ()
  19. word_pattern = do
  20. beam <- param (fS "word")
  21. html $ mconcat [fS "<h1>Scotty, ", beam, fS " me up!</h1>"]
  22. foo :: ActionM ()
  23. foo = do
  24. status ok200
  25. text $ T.pack "Blah"
  26. return ()
  27. logging :: Middleware
  28. logging = logStdout
  29. auth :: Middleware
  30. auth = basicAuth (\u p -> return $
  31. u == U8.fromString "michael" &&
  32. p == U8.fromString "mypass")
  33. (fS "My Realm")