1

I have this simple Wai/Warp application

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

How can I add a folder "images" to the route so that any image I'll be able to refer to any image from the index.html as "images/something.jpg"? I know how to add an exact route, but here I need to add a whole folder.

user7905648
  • 117
  • 6

1 Answers1

1

Network.Wai.Middleware.Static has a staticPolicy fn that takes a Policy and returns Middleware you can add to your Wai app. A Policy will define how the URI supplied by the user will be mapped to a filepath. Check out addBase for constructing a Policy; this may suit your needs just fine.

liminalisht
  • 1,243
  • 9
  • 11