2017-05-03 5 views
0

나는Wai/Warp에서 images/css/js 폴더를 서버하는 방법은 무엇입니까? 모든 이미지는 내가 "로 된 index.html에서 모든 이미지를 참조 할 수 있습니다 있도록

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 

가 어떻게 경로에 폴더"이미지 "를 추가 할 수 있습니다 간단한 와이/워프 응용 프로그램이 images/something.jpg "? 정확하게 경로를 추가하는 방법을 알고 있지만 전체 폴더를 추가해야합니다.

답변

0

Network.Wai.Middleware.StaticPolicy이며, 귀하는 Wai 앱에 추가 할 수있는 Middleware을 반환합니다. Policy은 사용자가 제공 한 URI를 파일 경로에 매핑하는 방법을 정의합니다. Policy 건설을 위해 addBase을 확인하십시오. 이것은 귀하의 요구에 잘 어울릴 수 있습니다.