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代码中,路由应该是什么样的?我完全迷失在这段代码中。
答案 0 :(得分:1)
我的理解是每条dir ...
行都是一条路线(对于一个目录。)
E.g:
dir "static" $ serveDirectory DisableBrowsing [] staticDir,
表示像/static/...
之类的路径调用处理程序serveDirectory ...
如果您想添加自己的路线,请在notFoundResponse
之前添加 - 否则可能永远不会被调用。