7

using the run from Network.Wai.Handler.Warp function to server rest api

run :: Port -> Application -> IO ()

but while doing post request, getting an error CORS header ‘Access-Control-Allow-Origin’. any idea how to overcome this in servant/haskell

gb.
  • 4,629
  • 1
  • 20
  • 19
khaled alomar
  • 673
  • 4
  • 25
  • 1
    This question: https://stackoverflow.com/questions/42143155/acess-a-servant-server-with-a-reflex-dom-client is not exactly the same but the answer might still be the answer you are looking for. – Dave Compton Nov 17 '17 at 21:25

1 Answers1

10

You could use wai-cors middleware to add CORS headers.

At the end you'll have something like

app = simpleCors $ serve api serverImpl

where

  • simpleCors is a Middleware from wai-cors
  • serve turns servant handlers into wai Application
  • api :: Proxy YourAPI
  • serverImpl is your handlers' implementation
phadej
  • 11,947
  • 41
  • 78