您是否有必要在内部ScottyM
而不是在开始之前运行 IO scotty
?
{-# LANGUAGE OverloadedStrings #-}
import Web.Scotty
import Data.Monoid (mconcat)
main = do
print "Hello world!" -- Or your IO action of choice
scotty 3000 $
get "/:word" $ do
beam <- param "word"
html $ mconcat ["<h1>Scotty, ", beam, " me up!</h1>"]
另一种选择是滥用notFound
并next
在 IO 中运行ActionM
,这更直接:
{-# LANGUAGE OverloadedStrings #-}
import Web.Scotty
import Control.Monad.Trans.Class (lift)
import Data.Monoid (mconcat)
main = scotty 3000 $ do
notFound $ do
lift $ print "Hello world!" -- Or some other IO action
next
get "/:word" $ do
beam <- param "word"
html $ mconcat ["<h1>Scotty, ", beam, " me up!</h1>"]