仆人缺少CORS标头"Access-Control-Allow-Origin" [英] CORS header ‘Access-Control-Allow-Origin’ missing in servant

查看:83
本文介绍了仆人缺少CORS标头"Access-Control-Allow-Origin"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Network.Wai.Handler.Warp 函数中的 run 到服务器rest api

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

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

但是在执行 post 请求时,出现错误 CORS标头"Access-Control-Allow-Origin" .任何想法如何克服仆人/haskell中的问题

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

推荐答案

您可以使用

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

最后,您会得到类似的东西

At the end you'll have something like

app = simpleCors $ serve api serverImpl

其中

  • simpleCors 是来自 wai-cors
  • 中间件
  • serve 将仆人处理程序转换为 wai Application
  • api ::代理YourAPI
  • serverImpl 是您的处理程序的实现
  • simpleCors is a Middleware from wai-cors
  • serve turns servant handlers into wai Application
  • api :: Proxy YourAPI
  • serverImpl is your handlers' implementation

这篇关于仆人缺少CORS标头"Access-Control-Allow-Origin"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆