Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CORS header ‘Access-Control-Allow-Origin’ missing in servant

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

like image 600
khaled omar Avatar asked Nov 17 '17 09:11

khaled omar


People also ask

Why is my Cors response missing the Access Control Allow Origin header?

The response to the CORS request is missing the required Access-Control-Allow-Origin header, which is used to determine whether or not the resource can be accessed by content operating within the current origin. If the server is under your control, add the origin of the requesting site to the set of domains permitted access by adding it to the ...

Is there a CORS header'Access-Control-Allow-Origin'header?

No 'Access-Control-Allow-Origin' header is present on the requested resource error 80 CORS header 'Access-Control-Allow-Origin' missing 135 API Gateway CORS: no 'Access-Control-Allow-Origin' header 131 Firebase Storage and Access-Control-Allow-Origin 850

How to enable Cors in Apache?

You need to set Access-Control-Allow-Origin Header to enable CORS in Apache. Here’s how to set Access-Control-Allow-Origin header in Apache.

How to allow CORS requests only for a specific domain?

Header set Access-Control-Allow-Origin "*" ... </Directory> In this case, the CORS requests will be allowed only for the domain whose .htaccess file you have modified. ... Header add Access-Control-Allow-Origin "*" ... In this case, the CORS requests will be allowed only for virtual host whose configuration file you have updated.


1 Answers

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
like image 105
phadej Avatar answered Sep 29 '22 11:09

phadej