【问题标题】:couchdb update handler with GET带有 GET 的 couchdb 更新处理程序
【发布时间】:2016-08-12 08:56:47
【问题描述】:

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

不幸的是,在一种情况下,我可以指定返回 URL,但不能指定method,并且方法始终是GET

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

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

我已经读过了

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

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

【问题讨论】:

    标签: couchdb


    【解决方案1】:

    假设它是通过浏览器传递的,则可以使用一些 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 生成一个表单,并返回 POSTs。发布版本被重写到更新处理程序。

    【讨论】:

    • 这个解决方案让我觉得很脏。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多