X-Git-Url: https://git.cworth.org/git?p=nodemuch;a=blobdiff_plain;f=example.js;h=fb57c915549157c8b4f0d78cc027853600db1526;hp=e6a084bbe2381b0974b704b90da5603f35af8ad6;hb=0f2625afe523247a0229511db1dbffba9dd560dc;hpb=7cce7aad03f20ee68e059bc6e84c07890485bb48 diff --git a/example.js b/example.js index e6a084b..fb57c91 100644 --- a/example.js +++ b/example.js @@ -1,12 +1,24 @@ var http = require( "http" ), - exec = require( "child_process" ).exec, - notmuch; + parse = require( "url" ).parse, + exec = require( "child_process" ).exec; http.createServer( function(req, res) { - var q = "wiki"; - notmuch = exec( "notmuch search " + q, function( error, stdout, stderr ) { - res.writeHead( 200, { "Content-Type": "text/plain" } ); - res.end( stdout ); - }); -} ).listen( 8124, "127.0.0.1" ); + 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"); + } +}).listen( 8124, "127.0.0.1" ); + console.log( "Server running at http://127.0.0.1:8124/" );