]> git.cworth.org Git - nodemuch/blob - example.js
Add a "show" action as well.
[nodemuch] / example.js
1 var http = require( "http" ),
2     parse = require( "url" ).parse,
3     exec = require( "child_process" ).exec;
4
5 http.createServer( function(req, res) {
6     var url = parse( req.url ),
7         action = url.pathname.split( "/" ).splice(-1)[0];
8     if ( action  === "search" ) {
9         exec( "notmuch search " + url.query, function( error, stdout, stderr ) {
10             res.writeHead( 200, { "Content-Type": "text/plain" } );
11             res.end( stdout );    
12         });
13     } else if ( action === "show" ) {
14         exec( "notmuch show " + url.query, function( error, stdout, stderr ) {
15             res.writeHead( 200, { "Content-Type": "text/plain" } );
16             res.end( stdout );    
17         });
18     } else {
19         res.writeHead( 404 );
20         res.end("404");
21     }
22 }).listen( 8124, "127.0.0.1" );
23
24 console.log( "Server running at http://127.0.0.1:8124/" );