cdepillabout / servant-rawm

Effectful Raw handler for Servant servers.
https://hackage.haskell.org/package/servant-rawm
BSD 3-Clause "New" or "Revised" License
16 stars 7 forks source link

Unable to use Servant.RawM based on documentation examples #24

Open saurabhnanda opened 1 year ago

saurabhnanda commented 1 year ago

Hi, I'm trying to write a raw webhook endpoint due to this complication in the Accept header. Here's what I've got:

data Env = Env {..} -- my application's reader environment
type AppM = ReaderT Env IO

type Routes = "lambda" :> "webhook" :> RawM

server :: ServerT Routes AppM
server = saveWebhookPayload

saveWebhookPayload :: AppM Wai.Application
saveWebhookPayload = do
  env_ <- getEnv
  pure $ \req respond -> do
     -- my Wai application here that uses the env_

I'm getting the following compiler error:

    • Couldn't match type ‘ServerT (RawM' FileServer) (ReaderT Env IO)’
                     with ‘ReaderT Env IO Application’
      Expected type: ServerT Routes AppM
        Actual type: AppM Application
    • In the expression: saveWebhookPayload
      In an equation for ‘server’: server = saveWebhookPayload

What am I doing wrong? Is this supposed to be used only for static file serving?

cdepillabout commented 1 year ago

@saurabhnanda Do you have a full project up on github I could clone and build in order to reproduce this error you're seeing?

If not, creating one would help me get into an environment where I could easily debug what's going on here.