如果你做不到
stack exec -- duckling-example-exe --port $PORT
,
exe/ExampleMain.hs
.
import System.Environment (lookupEnv)
...
main :: IO ()
main = do
setupLogs
tzs <- loadTimeZoneSeries "/usr/share/zoneinfo/"
p <- lookupEnv "PORT"
conf <- commandLineConfig $ maybe defaultConfig (`setPort` defaultConfig)
(p >>= readMaybe)
httpServe conf $
ifTop (writeBS "quack!") <|>
route
[ ("targets", method GET targetsHandler)
, ("parse", method POST $ parseHandler tzs)
]
改变并不太难,因为你可以在
source code
怎样
quickHttpServe
是实现的,添加端口有点麻烦,因为
setPort :: Int -> Config m a -> Config m a
Maybe Int
在这里会更方便。
自从
lookupEnv
Maybe String
我们可以用一元键
>>=
和
readMaybe
产生
可能是内景
.
该函数现在的工作方式如下:
-
如果没有
PORT
已设置环境变量,并且未选择给定默认值的命令行参数
-
如果有
--port 8080
PORT=9000
.