1

对不起我的基本问题,但我是 Haskell 的新手。

我正在按照此示例从请求正文中接收一些值,但我的服务器还使用以下代码从目录提供静态文件:

fileServing :: ServerPart Response
fileServing = serveDirectory EnableBrowsing ["index.html"] "./Path/"

mainFunc = simpleHTTP nullConf $ msum [ 
                                        fileServing                                     
                                      ]

我将以下代码添加到我的库中,但我不确定在哪里使用该handlers函数,因为我已经msummainFunc.

handlers :: ServerPart Response
handlers =
    do decodeBody myPolicy
       msum [ 
               myGetData
            ]

myGetData :: ServerPart Response
myGetData =
    do method POST
       username <- look "username"
       password <- look "password"
       ok $ toResponse (username ++ ", " ++ password)
4

1 回答 1

1

fileServing, myGetData, msum [fileServing],msum [myGetData]并且handlers都具有ServerPart Response类型,这是您传递给的simpleHTTP nullConf类型mainFunc。既然如此,你可能想要...

mainFunc = simpleHTTP nullConf handlers

-- etc.

handlers :: ServerPart Response
handlers =
    do decodeBody myPolicy
       msum [ fileServing
            , myGetData
            ]

msum这里将处理程序列表组合成单个处理程序(注意,这也意味着msum在具有单个处理程序的列表上是多余的)。

于 2018-02-12T05:09:00.933 回答