8

I am running a Spock server and wanting to serve some static content. I am using respondMiddleware function from the "Web.Spock.Action" package.

The signature is:

    respondMiddleware :: Monad m => Middleware -> ActionCtxT ctx m a

I am getting this "Middleware" using the staticPolicy function from "Network.Wai.Middleware.Static" package

    staticPolicy :: Policy -> Middleware

And the "Policy" using addBase from "Network.Wai.Middleware.Static" package

    addBase :: String -> Policy

Here is my codeblock:

    get ("/") $
      respondMiddleware $ staticPolicy $ addBase ("static")

The static has an index.html and the related JS and CSS files and it is placed in the root directory of the stack project. The error I get is Failed to load resource: the server responded with a status of 400 (Bad Request)

  • 2
    It's been a while since I've used Spock, so this may be wrong: The path `"/"` in your RouteSpec doesn't have a wildcard, so I think that will only match *exactly* `/`. I suspect what you want is `middleware $ staticPolicy $ addBase "static"`. – Chris Martin Dec 06 '17 at 09:36

1 Answers1

2

The right way to do this is using the html function from the Web.Spock.Action package.

I used a jinja templating using ginger to parameterize my html file and then served it using the html function.

import qualified Web.Spock.Action as SA

serveHtml :: JinjaTemplate -> SA.ActionT (LoggingT IO) ()
serveHtml tmplt = SA.html tmplt