我有这个简单的WAI/WARP应用程序
app :: Wai.Application
app req respond = respond $ case Wai.rawPathInfo req of
"/" -> Wai.responseFile status200 [("Content-Type", "text/html")] "views/index.html" Nothing
_ -> notFound
notFound :: Wai.Response
notFound = Wai.responseLBS status404 [("Content-Type", "text/plain")] "404 - Not Found"
main :: IO ()
main = do
port <- getEnv "PORT"
let setting = Warp.setPort (read port :: Int) Warp.defaultSettings
putStrLn $ "start server on the port " ++ port
Warp.runSettings setting app
如何将文件夹"图像"添加到路由上,以便我能够将任何图像从index.html中引用为" images/sosings.jpg"?我知道如何添加确切的路由,但是在这里我需要添加一个完整的文件夹。
network.wai.middleware.static具有staticPolicy
FN,该FN采用Policy
并返回Middleware
您可以添加到WAI应用中。Policy
将定义用户提供的URI如何映射到FilePath。查看addBase
构建Policy
;这可能适合您的需求。