使用GET的couchdb更新处理程序

时间:2016-08-12 00:19:18

标签: couchdb

使用CouchDB,我试图与某些第三方服务集成。我一直在使用更新处理程序,因此我可以记录对数据库的响应。

不幸的是,在一种情况下,我可以指定返回网址,但我无法指定method,方法始终为GET

{
  error: "method_not_allowed",
  reason: "Update functions do not allow GET"
}

有人知道解决方法吗?我可以使用另一个处理程序吗?其他人似乎都不允许写文件。

我已经读过这个

https://lbl.io/post/url-shortening-with-couchdb

我希望避免创建代理,我正在使用托管服务(smileupps),因此没有自定义。

1 个答案:

答案 0 :(得分:0)

假设它正在通过浏览器,则可以使用一些javascript和html。这不会处理(例如)使用非javascript / html支持客户端的任何情况

设置rewrites

{
    "from": "/endpoint",
    "to": "proxy.html",
    "method": "GET",
    "query": {}
},
{
    "from": "/endpoint",
    "to": "_update/endpoint",
    "method": "*",
    "query": {}
}

proxy.html

<html>
<body>
<form method='POST'></form>
<script>
var form = document.getElementsByTagName("form")[0];
form.setAttribute("action", window.location);
form.submit();
</script>
</body>
</html>

通知会发送到发送给代理的endpoint。代理使用完全相同的URL生成表单,并返回POST。 post版本被重写为更新处理程序。

相关问题