Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using CouchDB to serve HTML

Tags:

json

rest

couchdb

I'm trying to use CouchDB with HTML/standalone REST architecture. That is, no other app server other than CouchDB and ajax style javascript calling CouchDB.

It looks like cross scripting is a problem. I was using Cloudkit/Tokyo Cabinet before and it seems like the needed callback function was screwing it up in the URL.

Now I'm trying CouchDB and getting the same problem.

Here are my questions:

1) Are these problems because the REST/JSON store like CouchDB or CloudKit is running on a different port from my web page? They're both run locally and called from "localhost".

2) Should I let CouchDB host my page and serve the HTML?

3) How do I do this? The documentation didnt seem so clear...

Thanks, Alex

like image 950
alxross Avatar asked Dec 15 '09 23:12

alxross


3 Answers

There is a simple answer: store static HTML as attachments to CouchDB documents. That way you can serve the HTML directly from the CouchDB.

There is a command-line tool to help you do this, called CouchApp

The book Mikeal linked to also has a chapter (Managing Design Documents) on how to use CouchApp to do this.

like image 195
J Chris A Avatar answered Sep 22 '22 15:09

J Chris A


3) you can use CouchDB shows to generate HTML (or any content type)

like image 23
mykhal Avatar answered Sep 23 '22 15:09

mykhal


There are huge advantages to having CouchDB serve/generate your HTML.

For one thing, the pages (which are HTTP resources) are tied to the data or to the queries on the data and CouchDB knows when to update the etag when the page has changed. This means that if you stick nginx in front of CouchDB and say "cache stuff" you get all the free caching you would normally need to build yourself.

I would push for nginx > apache in front of CouchDB because Apache isn't all that great at handling concurrent connections and nginx + erlang (CouchDB) are great at it.

Also, you can write these views in JavaScript which are documented well in the CouchDB book http://books.couchdb.org/relax/ or in Python using my view server http://github.com/mikeal/couchdb-pythonviews which isn't really documented at all yet but I'll be getting to it soon :)

I hope that view servers in other languages start implementing the new features in the view server protocol as well so that anyone can write standalone apps in CouchDB.

like image 38
mikeal Avatar answered Sep 23 '22 15:09

mikeal