Created
October 21, 2013 16:35
-
-
Save zarac/7086830 to your computer and use it in GitHub Desktop.
couchapp app.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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