如何在使用Scotty时写入文件?

时间:2016-12-06 13:07:19

标签: http haskell scotty

我在使用Scotty时写入文件时遇到问题。我完成了" Hello World"示例很容易,但当我尝试根据POST请求的输入写入文件时,我得到了404页。

我尝试使用appendFile的重要部分:

homep :: ScottyM ()
homep = do
    get "/search/:word" showResults
    post "/add/:word" updateFile

updateFile :: ActionM ()
updateFile = do
    beam <- param "word"
    updated <- liftIO (update (forceEither (parseParam beam)))
    case updated of
        Just worked -> do
            --json $ object [ "ok" .= ("ok" :: String) ]
            html $ mconcat ["<h1>Scotty, ", "I worked!</h1>"]
        Nothing -> do
            html $ mconcat ["<h1>Scotty, ", "I broke!</h1>"]

update :: Text -> IO (Maybe String)
update x = (Data.Text.Lazy.IO.appendFile "rewr.txt" x) >> return (Just "Success")

我在一个非常简单的主语句中将appendFile单独用于另一个文件中,所以我认为我对该函数的理解是不错的。我的问题是否与param没有返回需要传递给appendFile的内容?

另外,我/搜索网址工作正常;它只是显示html中页面/搜索/后面的内容。这是代码:

showResults :: ActionM ()
showResults = do
    beam <- param "word"
    html $ mconcat ["<h1>Scotty, ", beam, " me up!</h1>"]

0 个答案:

没有答案