Skip to content

Instantly share code, notes, and snippets.

@sebastianrothbucher
Last active August 29, 2015 14:06
Show Gist options
  • Save sebastianrothbucher/4135733751d39909fe54 to your computer and use it in GitHub Desktop.
Save sebastianrothbucher/4135733751d39909fe54 to your computer and use it in GitHub Desktop.
Serving HTML from a CouchDB doc

Want do use Futon or Fauxton to manage web content? here is how you do that:

{
   "_id": "_design/showfkt",
   "_rev": "11-e00cd0ba76460fe57dd767e125e6a9c4",
   "language": "javascript",
   "shows": {
       "htmlout": "function(doc, req){return doc.html;}"
   }
}

along with

{
   "_id": "htmltest",
   "_rev": "1-0477538df103292200c5c1e9ba1101d8",
   "html": "<html><h2>Sers</h2></html>"
}

Call via http://localhost:5984/test/_design/showfkt/_show/htmlout/htmltest

"htmlout" is very simple though - you can create advanced functions providing some HTML already or combining several document fields. (Think about "angularctrl" as a field for an AngularJS controller, for instance). You can upload angular.js to a doc and get started providing an app (including e.g. Jasmine tests) by working with several "html" like fields in your doc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment