You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by Apache Wiki <wi...@apache.org> on 2018/04/12 14:13:12 UTC
[Couchdb Wiki] Update of "ServingApplications" by JoanTouzet
Dear wiki user,
You have subscribed to a wiki page "Couchdb Wiki" for change notification.
The page "ServingApplications" has been deleted by JoanTouzet:
https://wiki.apache.org/couchdb/ServingApplications?action=diff&rev1=5&rev2=6
- #redirect How_to_serve_applications
- ## page was renamed from ServingAppsFromCouchDb
- You can write applications that are written entirely in HTML/CSS and JavaScript and that is stored within CouchDB document attachments. Here's a short script that makes it easy to wrap up a bunch of files and put them into a database.
- This is a quick'n'dirty hack. All you need to do is fill the {{{$files}}} array with entries of {{{$file}}} arrays that contain the filename and content-type of that file.
-
- Run with:
- $ curl -X PUT http://server:5984/database/document -d "\`php upload.php\`"
-
- {{{
- <?php
- $file["name"] = "main.html";
- $file["contentType"] = "text/html";
- $files[] = $file;
-
- $file["name"] = "thread.html";
- $file["contentType"] = "text/html";
- $files[] = $file;
-
- $file["name"] = "styles.css";
- $file["contentType"] = "text/css";
- $files[] = $file;
-
- $file["name"] = "DetectWebkit.js";
- $file["contentType"] = "application/javascript";
- $files[] = $file;
-
- foreach($files AS $file) {
- $file["data"] = base64_encode(file_get_contents($file["name"]));
-
- $attachments[] = <<<EOF
- "$file[name]": {
- "content-type":"$file[contentType]",
- "data":"$file[data]"
- }
- EOF;
- }
-
- $attachments = implode(",\n\n", $attachments);
-
- $document = <<<EOF
- {
- "_attachments": {
- $attachments
-
- }
- }
-
- EOF;
- echo $document;
- ?>
- }}}
-