没有服务器端的 CouchApp 或有 xdomain 问题的 CouchDB 后端?
我已经使用 CouchDB 和 CouchApp 一段时间了。我计划将它用于我正在开发的一个新网站项目。
从可扩展性的角度来看,我喜欢 CouchApp 的想法。
缺点是,由于没有服务器端代码,有些事情(例如 oAuth 身份验证)很难在客户端完成。在某些时候,我确信我将需要一些具有某种描述的服务器端代码 - 我想您可以查看 Node.js,但此时不希望这样做。
使用 CouchDB 纯粹作为后端解决方案,而您的页面由另一台服务器提供服务也是一个很好的选择,但缺点是跨域问题使您无法轻松使用内置的 CouchDB API。
那么有人能解决这两个缺点之一吗?
您能否以某种方式从 CouchApp 提供服务器端代码(甚至 PHP 也将是一个胜利),或者您能否以某种方式使用单独的站点来为您的页面提供服务但克服跨域问题?
我真的试图让解决方案尽可能干净(和可扩展),CouchDB 的伟大之处之一就是超级简单、超级快速的 API,所以我真的不想在它周围使用包装器 - 除非它不这样做不妨碍性能/可扩展性。
欢迎您提出意见。
I have been playing with CouchDB and CouchApp for a little while now. I am planning on using it for a new web site project I'm working on.
From a scalability viewpoint I love the idea of CouchApp.
The downside is that with no server side code there are some things (like oAuth authentication) that are hard to do on the client side. At some point I'm sure I will need some server side code of some description - I guess you can then look at Node.js but would rather not at this point.
Using CouchDB purely as a backend solution while your pages are served from another server is also a great fit but the downside here is that the cross domain issues prevent you from easily using the built in CouchDB API.
So does anyone have a solution to one of these two downsides?
Can you somehow serve server side code (even PHP would be a win) from CouchApp or can you somehow use a separate site to serve your pages but overcome the cross domain issue?
I am really trying to keep the solution as clean (and as scalable) as possible and one of the great things about CouchDB is the super simple, super fast API so I don't really want to use a wrapper around it - unless it doesn't hinder the performance/scalability.
Your opinions are welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于 CouchDB 使用基于 HTTP 的 API,因此有多种方法可以将服务器端代码(node.js、PHP 等)与 CouchApp 进行“混合和匹配”。
我将这些选项分为三类:
您可以在下面找到有关 _changes feed 和 _external 处理程序的更多信息:
就其价值而言,我将在下周三的 PHP 和 CouchDB 网络广播。您的问题将为网络广播结束时的讨论提供宝贵的补充。
我很想知道您的 CouchApp 结果如何,以及您如何解决上述问题。
Because CouchDB uses an HTTP-based API there are several ways to "mix and match" server-side code (node.js, PHP, etc) with your CouchApp.
I break the options down into three categories:
You can find out more about the _changes feed and _external handlers below:
For what its worth, I'll be discussing these three options this coming Wednesday in a PHP and CouchDB Webcast. Your questions would be a valuable addition to the discussion at the end of the webcast.
I'd love to know how your CouchApp turns out, and how you solve the problems you mentioned above.
BigBlueHat 的回答非常好,但我还有一个可能的选择要添加:
克服跨域问题,从而允许您从任何类型的 Web 服务器提供页面,并允许浏览器直接与 CouchDB 交互(这可以是在另一台服务器上)。
由浏览器强制执行的跨域限制并不难绕过。
我知道的两种主要方法是:JSONP 和 CORS。
JSONP 将每个请求伪装为“脚本”请求(因为脚本请求不受跨域规则的约束)。它仅适用于 GET,不适用于 POST 或 PUT 或其他任何内容。您可以使用 jQuery 来完成。
CORS 是“跨源资源共享”,它只是一个必须在服务器(本例中为 couchdb)上实现的特殊 HTTP 标头,它告诉浏览器它没问题——它不介意服务来自以下位置的请求:另一个域。我已经对此进行了测试,它确实有效,但可能存在安全问题 - 我不确定。
所以...我不知道这是否是一个好主意,但技术上可以(至少部分地)克服 CouchDB 的跨域限制。有人曾经使用这种类型的设置构建过系统吗?
Excellent answer from BigBlueHat, but I have one more more possible option to add:
Overcome the cross-domain problem, thereby allowing you to serve pages from any sort of web server, and also allowing the browser to interact directly with CouchDB ( which can be on another server ).
The cross-domain restriction, as enforced by browsers, is not that hard to get around.
The 2 main methods that I know of are: JSONP and CORS.
JSONP disguises each request as "script" request ( as script requests are exempt from the cross-domain rule). It only works for GET, not POST or PUT or anything else. You can do it with jQuery.
CORS is "Cross Origin Resource Sharing", and it is simply a special HTTP Header that must be implemented on the server ( couchdb in this case ), which tells the browser that it's OK -- it doesn't mind serving requests that come from another domain. I have tested this, and it does work, but there might be security issues -- I am not sure.
So...I don't know whether it's a good idea, but it is technically possible to ( at least partially ) overcome the cross-domain restriction with CouchDB. Has anyone ever built a system using this type of setup?