本文介绍了我如何使用wai-handler-devel和一个简单的wai应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有使用wai的基本的hello world应用程序设置,并且想使用wai-handler-devel,但我不确定如何处理它,并且无法在wai项目的使用中找到它的任何示例。 { - #LANGUAGE OverloadedStrings# - } import Network.Wai import Network.HTTP.Types 导入Network.Wai.Handler.Warp(运行)导入Data.ByteString.Lazy.Char8() - 仅适用于孤儿实例 app :: Application app _ = return $ responseLBS status200 [(Content-Type,text / plain)] Hello,World! main :: IO() main = do putStrLn $http:// localhost:8080 /运行8080 app 我需要做些什么才能让wai-handler-devel与基本的wai应用程序一起工作? 注意:这里有一个修正( https://gist.github .com / 1499226 )如果遇到wai-handler-devel:command not found的问题解决方案 wai-handler-devel的 Hackage页面表示应该从命令中调用它像这样: $ wai-handler-devel< port> My.App.Module myApp 并且您的应用程序的类型必须如下所示: myApp ::(应用程序 - > IO()) - > IO() 在这种情况下,您应该定义 myApp myApp ::(Application - > IO()) - > IO() myApp处理程序=处理程序应用程序 尽管您可能想内联 $ b $ pre $ my $ myApp ::(应用程序 - > IO()) - $ c $ app> / code> > IO() myApp处理程序=处理程序$ \_ - >返回$ responseLBS status200 [(Content-Type,text / plain)] Hello,World! 类型是这样的,所以你可以在启动时进行初始化等等。 C $ C> IO 。我建议您阅读 SmallApp 和 wai-handler-devel的git仓库中的FullApp 示例;后者特别有用,因为它具有显示重载期间代码流的调试输出,并显示如何集成长时间运行的数据库连接。 运行脚本也显示如何以编程方式使用wai-handler-devel,包括手动指定哈姆雷特模板依赖关系(其中 wai-handler-devel 命令行工具自动确定)。 然后,您应该能够按如下方式重写您的 main : main :: IO() main = do putStrLn $http:// localhost:8080 / myApp(run 8080) 当然,您可以轻松地将运行函数从 wai-handler-fastcgi , wai-handler-scgi 或甚至是 wai-handler -webkit 。 I have the basic "hello world" application setup using wai, and would like to use wai-handler-devel, but am unsure how to go about it and can't find any examples of it in usage on a wai project. {-# LANGUAGE OverloadedStrings #-}import Network.Waiimport Network.HTTP.Typesimport Network.Wai.Handler.Warp (run)import Data.ByteString.Lazy.Char8 () -- Just for an orphan instanceapp :: Applicationapp _ = return $ responseLBS status200 [("Content-Type", "text/plain")] "Hello, World!"main :: IO ()main = do putStrLn $ "http://localhost:8080/" run 8080 appWhat do I need to do to get wai-handler-devel working with a basic wai app?Note: There is a fix here ( https://gist.github.com/1499226) i f you run into issues with "wai-handler-devel: command not found" 解决方案 wai-handler-devel's Hackage page says that it should be invoked from the command-line like so:$ wai-handler-devel <port> My.App.Module myAppand that your application's type must look like this:myApp :: (Application -> IO ()) -> IO ()In this case, you should define myApp as follows:myApp :: (Application -> IO ()) -> IO ()myApp handler = handler appalthough you may want to inline app entirely:myApp :: (Application -> IO ()) -> IO ()myApp handler = handler $ \_ -> return $ responseLBS status200 [("Content-Type", "text/plain")] "Hello, World!"The type is like this so that you can do initialisation on start-up and the like in IO. I suggest reading the SmallApp and FullApp examples from wai-handler-devel's git repository; the latter is especially helpful, as it has debug output showing the flow of the code during a reload, and shows how to integrate a long-running database connection.The run script for the FullApp example also shows how to use wai-handler-devel programmatically, including manually specifying Hamlet template dependencies (which the wai-handler-devel command-line tool determines automatically).You should then be able to rewrite your main as follows:main :: IO ()main = do putStrLn $ "http://localhost:8080/" myApp (run 8080)Of course, you could just as easily pass the run function from wai-handler-fastcgi, wai-handler-scgi or even wai-handler-webkit. 这篇关于我如何使用wai-handler-devel和一个简单的wai应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-14 04:30