简体   繁体   English

如何从CouchDB中的服务器端JavaScript加载静态资源

[英]How to load static resources from server-side javascript in CouchDB

For CouchDB, I know that show function can generate HTMLs / Images / XML feed on the fly. 对于CouchDB,我知道show function可以动态生成HTML / Images / XML feed。

While in that case they have to be in the script itself and encoded (eg base 64 for image), as in here 在这种情况下,它们必须在脚本本身中并进行编码(例如,图像的基数为64), 如此处所示

What is the best way to load static resources which are attachments of design documents eg As simple as JSON, or Images and process with server-side javascript? 加载作为设计文档附件的静态资源(例如JSON或Images)并使用服务器端javascript处理的最佳方法是什么?

The script file itself is an attachment in the design doc. 脚本文件本身是设计文档中的附件。 The variable doc is not available. 变量doc不可用。

Are there any way similar to node.js for it? 有什么类似于node.js的方法吗? or we use trick in context like _show or _list to show the document with id: _design/ddoc ? 或者我们在_show或_list之类的上下文中使用技巧来显示ID为_design / ddoc的文档?

doing REST request inside that environment I believe is also not possible as XMLHttpRequest is also not available. 我相信在该环境中执行REST请求也是不可能的,因为XMLHttpRequest也不可用。 Establishing DB connection is also not possible? 也无法建立数据库连接?

This supposed to be a simple question, I wonder I am missing something in couchDB? 这应该是一个简单的问题,我想知道我在bedDB中缺少了什么吗?

In order to serve a website directly, you need to use url rewrites . 为了直接为网站提供服务,您需要使用url rewrites You'd rewrite / to got to one of your show functions . 您需要重写/进入表演功能之一 to bootstrap your site with basic HTML and JS (embedded probably). 使用基本的HTML和JS(可能嵌入)引导您的网站。

A lot of this work has been done already by CouchApps (basic tutorial here ). CouchApps已经完成了很多工作( 此处是基础教程 )。 This is by far the easiest way to get started. 到目前为止,这是最简单的入门方法。 This seems to be the way http://npmjs.org is served. 似乎http://npmjs.org的投放方式。

This isn't the place for a walkthrough, so hopefully this gives you enough information to get started. 这不是演练的地方,因此希望它可以为您提供足够的信息以开始使用。

If your site needs server-side logic (websockets for example), this solution won't work for you. 如果您的站点需要服务器端逻辑(例如websockets),则此解决方案将对您不起作用。 All you get with a couch app is a database, HTML, CSS and Javascript. 沙发应用程序为您提供的只是一个数据库,HTML,CSS和Javascript。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM