Skip to content

Instantly share code, notes, and snippets.

@zarac
Created October 21, 2013 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zarac/7086830 to your computer and use it in GitHub Desktop.
Save zarac/7086830 to your computer and use it in GitHub Desktop.
couchapp app.js
var couchapp = require('couchapp')
var path = require('path')
var ddoc = {
_id : "_design/index",
rewrites : [
{ from : '',
to : '_list/tags/tag' },
{ from : '*',
to : '*' } ],
lists : {
article : function(head, req) {
send('<html><body>')
start({
'headers': {
'Content-Type': 'text/html' } })
while (row = getRow()) {
send('<article>' + row.key + '</article>') }
send('</body></html>') } },
views : {
url : {
map : function(doc) {
if (doc.url)
emit([doc.url, doc.born], doc) } },
tag : {
map : function(doc) {
if (doc.url && doc.tags) {
for (var i = 0; i < doc.tags.length; i++)
emit(doc.tags[i], doc) } } },
attachments : {
map : function(doc) {
if (doc._attachments)
emit(doc.url, doc._attachments) } } },
validate_doc_update : function (newDoc, oldDoc, userCtx) {
if (newDoc._deleted === true && userCtx.roles.indexOf('_admin') === -1)
throw "Only admin can delete documents on this database." } }
couchapp.loadAttachments(ddoc, path.join(__dirname, 'static'));
module.exports = ddoc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment