{-# LANGUAGE OverloadedStrings #-} {-# language DeriveAnyClass #-} {-# language ScopedTypeVariables #-} module Main (main) where import Web.Scotty import Network.Wai.Middleware.RequestLogger -- install wai-extra if you don't have this import Control.Exception (Exception(..)) import Control.Monad import Control.Monad.Trans import System.Random (newStdGen, randomRs) import Network.HTTP.Types (status302) import Data.Text.Lazy (pack) import Data.Text.Lazy.Encoding (decodeUtf8) import Data.String (fromString) import Data.Typeable (Typeable) data Err = Boom | UserAgentNotFound | NeverReached deriving (Show, Typeable, Exception) main :: IO () main = scotty 3000 $ do -- Add any WAI middleware, they are run top-down. middleware logStdoutDev -- get (function $ \req -> Just [("version", T.pack $ show $ httpVersion req)]) $ do -- v <- param "version" -- text v -- To demonstrate that routes are matched top-down. get "/" $ text "foobar" get "/" $ text "barfoo" -- Using a parameter in the query string. Since it has -- not been given, a 500 page is generated. get "/foo" $ do v <- captureParam "fooparam" html $ mconcat ["