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
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 ...
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
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.
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.
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' implementationIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With