Skip to content

Instantly share code, notes, and snippets.

@zarac

zarac/app.js

Created Oct 21, 2013
Embed
What would you like to do?
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