Creating a route for static assets or images in Hasekll Spock

350 Views Asked by At

I have this basic Spock application taken from its website:

main :: IO ()
main =
    do ref <- newIORef 0
       spockCfg <- defaultSpockCfg EmptySession PCNoDatabase (DummyAppState ref)
       runSpock 8080 (spock spockCfg app)

app :: SpockM () MySession MyAppState ()
app =
    do get root $
           text "Hello World!"
       get -- ??? route for "/img/"???

I have an html page which I can return like this:

However, an html page contains a some "img" tags. How do I need to create a route so that the images resolves? Say, the images are location in the folder "img".

1

There are 1 best solutions below

0
On

Something I like to do is to use the wai-middleware-static middleware to serve a static directory :

app :: SpockM () MySession MyAppState ()
app = do
    middleware $ staticPolicy (addBase "static")
    ...