]> git.cworth.org Git - nodemuch/commitdiff
Add a "show" action as well.
authorCarl Worth <cworth@cworth.org>
Sun, 5 Dec 2010 11:21:23 +0000 (03:21 -0800)
committerCarl Worth <cworth@cworth.org>
Sun, 5 Dec 2010 11:21:23 +0000 (03:21 -0800)
Much like search, but calling "notmuch show" instead.

example.js

index 74e5701bd0c9137dcc33c63ada953e109e397b36..fb57c915549157c8b4f0d78cc027853600db1526 100644 (file)
@@ -3,12 +3,18 @@ var http = require( "http" ),
     exec = require( "child_process" ).exec;
 
 http.createServer( function(req, res) {
-    var url = parse( req.url );
-    if ( url.pathname.split( "/" ).splice(-1)[0] === "search" ) {
+    var url = parse( req.url ),
+        action = url.pathname.split( "/" ).splice(-1)[0];
+    if ( action  === "search" ) {
         exec( "notmuch search " + url.query, function( error, stdout, stderr ) {
             res.writeHead( 200, { "Content-Type": "text/plain" } );
             res.end( stdout );   
         });
+    } else if ( action === "show" ) {
+        exec( "notmuch show " + url.query, function( error, stdout, stderr ) {
+            res.writeHead( 200, { "Content-Type": "text/plain" } );
+            res.end( stdout );   
+        });
     } else {
         res.writeHead( 404 );
        res.end("404");