开发者

Allowing POSTs to static files in a CouchDB CouchApp

When serving static assets from a CouchApp (e.g. HTML and JS for a Backbone.js app), a 405 Method Not Allowed error is appropriately kicked when those static pages are POSTed to. However, when developing a Facebook app for canvas/iframe, Facebook sends all requests as开发者_JAVA技巧 POSTs. Is there any way to make Couch allow the POST method?


I am pessimistic about this. I'm not sure but it may not be possible.

Is it possible to tell Facebook to add custom headers? Couch supports an X-HTTP-Method-Override header in POST requests. Just set it to the HTTP method you really wanted.


I ran into the same issue, and so far I was able to avoid another hoster by simply letting CouchDB output javascript that redirects my request (so basically the client's browser).

As @JasonSmith commented, _show functions are able to receive POST methods; so I've basically created a new _show function called shows/proxy.js which (in it's most basic functionality) only includes this:

function(doc, req) {
   return "<script>document.location='TARGETURL';</script>";    
}

Replace TARGETURL with your real Canvas URL page. Then I setup the FB Canvas URL to point to this page,

http://fbdemo.iriscouch.com/fbdemo/_design/fbdemo/_show/proxy?

This works just fine in the FB Canvas, and finally shows my CouchApp! Next step is to start passing QueryString parameters from FB (depending on login, graph, etc...), but I'll leave that as an exercise to our readers ;-)

Hope this helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜