Happstack 代码中的 Route 应该是什么样的?
What should a Route look like in Happstack code?
runServer :: IO ()
runServer = do
configureLogger
staticDir <- getStaticDir
redirectUrlGraphEmail <- retrieveAuthURL testUrl
redirectUrlGraphPost <- retrieveAuthURL testPostUrl
aboutContents <- LazyIO.readFile $ markdownPath ++ "README.md"
privacyContents <- LazyIO.readFile $ markdownPath ++ "PRIVACY.md"
-- Start the HTTP server
simpleHTTP serverConf $ do
decodeBody (defaultBodyPolicy "/tmp/" 4096 4096 4096)
msum [ do
nullDir
seeOther "graph" (toResponse "Redirecting to /graph"),
dir "grid" gridResponse,
dir "graph" graphResponse,
dir "image" graphImageResponse,
dir "timetable-image" $ look "courses" >>= \x -> look "session" >>= timetableImageResponse x,
dir "graph-fb" $ seeOther redirectUrlGraphEmail $ toResponse "",
dir "post-fb" $ seeOther redirectUrlGraphPost $ toResponse "",
dir "test" $ look "code" >>= getEmail,
dir "test-post" $ look "code" >>= postToFacebook,
dir "post" postResponse,
dir "draw" drawResponse,
dir "about" $ aboutResponse aboutContents,
dir "privacy" $ privacyResponse privacyContents,
dir "static" $ serveDirectory DisableBrowsing [] staticDir,
dir "course" $ look "name" >>= retrieveCourse,
dir "all-courses" $ liftIO allCourses,
dir "graphs" $ liftIO queryGraphs,
dir "course-info" $ look "dept" >>= courseInfo,
dir "depts" $ liftIO deptList,
dir "timesearch" searchResponse,
dir "calendar" $ lookCookieValue "selected-lectures" >>= calendarResponse,
dir "get-json-data" $ look "graphName" >>= \graphName -> liftIO $ getGraphJSON graphName,
dir "loading" $ look "size" >>= loadingResponse,
dir "save-json" $ look "jsonData" >>= \jsonStr -> look "nameData" >>= \nameStr -> liftIO $ saveGraphJSON jsonStr nameStr,
notFoundResponse
]
在函数msum之后的列表中(我假设它是一个列表,因为它在[]中),dir之后的所有内容都是路由吗? happstack 代码中的路由应该是什么样的?我完全迷失在这段代码中。
我的理解是每dir ...
行是一个路由(对于一个目录。)
例如:
dir "static" $ serveDirectory DisableBrowsing [] staticDir,
意味着对于像 /static/...
这样的路径调用处理程序 serveDirectory ...
如果您想添加自己的路由,请在 notFoundResponse
之前添加它 - 否则它可能永远不会被调用。
runServer :: IO ()
runServer = do
configureLogger
staticDir <- getStaticDir
redirectUrlGraphEmail <- retrieveAuthURL testUrl
redirectUrlGraphPost <- retrieveAuthURL testPostUrl
aboutContents <- LazyIO.readFile $ markdownPath ++ "README.md"
privacyContents <- LazyIO.readFile $ markdownPath ++ "PRIVACY.md"
-- Start the HTTP server
simpleHTTP serverConf $ do
decodeBody (defaultBodyPolicy "/tmp/" 4096 4096 4096)
msum [ do
nullDir
seeOther "graph" (toResponse "Redirecting to /graph"),
dir "grid" gridResponse,
dir "graph" graphResponse,
dir "image" graphImageResponse,
dir "timetable-image" $ look "courses" >>= \x -> look "session" >>= timetableImageResponse x,
dir "graph-fb" $ seeOther redirectUrlGraphEmail $ toResponse "",
dir "post-fb" $ seeOther redirectUrlGraphPost $ toResponse "",
dir "test" $ look "code" >>= getEmail,
dir "test-post" $ look "code" >>= postToFacebook,
dir "post" postResponse,
dir "draw" drawResponse,
dir "about" $ aboutResponse aboutContents,
dir "privacy" $ privacyResponse privacyContents,
dir "static" $ serveDirectory DisableBrowsing [] staticDir,
dir "course" $ look "name" >>= retrieveCourse,
dir "all-courses" $ liftIO allCourses,
dir "graphs" $ liftIO queryGraphs,
dir "course-info" $ look "dept" >>= courseInfo,
dir "depts" $ liftIO deptList,
dir "timesearch" searchResponse,
dir "calendar" $ lookCookieValue "selected-lectures" >>= calendarResponse,
dir "get-json-data" $ look "graphName" >>= \graphName -> liftIO $ getGraphJSON graphName,
dir "loading" $ look "size" >>= loadingResponse,
dir "save-json" $ look "jsonData" >>= \jsonStr -> look "nameData" >>= \nameStr -> liftIO $ saveGraphJSON jsonStr nameStr,
notFoundResponse
]
在函数msum之后的列表中(我假设它是一个列表,因为它在[]中),dir之后的所有内容都是路由吗? happstack 代码中的路由应该是什么样的?我完全迷失在这段代码中。
我的理解是每dir ...
行是一个路由(对于一个目录。)
例如:
dir "static" $ serveDirectory DisableBrowsing [] staticDir,
意味着对于像 /static/...
这样的路径调用处理程序 serveDirectory ...
如果您想添加自己的路由,请在 notFoundResponse
之前添加它 - 否则它可能永远不会被调用。