0
votes

Using CouchDB, I am attempting to integrate with some third-party services. I have been using an update handler so I can record the responses to the database.

Unfortunately, in one case, I can specify the return URL, but I can't specify the method, and the method is always GET.

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

Is anyone aware of a workaround? Is there another handler I could be using? None of the others seem to allow for writing a document.

I have read this

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

I was hoping to avoid creating a proxy, and I'm using a hosted service (smileupps) so no customizations.

1

1 Answers

0
votes

Assuming it is passing through a browser, it is possible to use some javascript and html. This does not handle any cases that (for example) use non-javascript/html supporting clients

Setup your 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>

What happens is the notification is sent to endpoint which is sent to the proxy. The proxy generates a form using the exact same URL and POSTs it back. The post version is rewritten to the the update handler.