简体   繁体   中英

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.

While in that case they have to be in the script itself and encoded (eg base 64 for image), as in here

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?

The script file itself is an attachment in the design doc. The variable doc is not available.

Are there any way similar to node.js for it? or we use trick in context like _show or _list to show the document with id: _design/ddoc ?

doing REST request inside that environment I believe is also not possible as XMLHttpRequest is also not available. Establishing DB connection is also not possible?

This supposed to be a simple question, I wonder I am missing something in couchDB?

In order to serve a website directly, you need to use url rewrites . You'd rewrite / to got to one of your show functions . to bootstrap your site with basic HTML and JS (embedded probably).

A lot of this work has been done already by CouchApps (basic tutorial here ). This is by far the easiest way to get started. This seems to be the way http://npmjs.org is served.

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. All you get with a couch app is a database, HTML, CSS and Javascript.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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