]> git.cworth.org Git - nodemuch/blob - example.js
Get query string from server request.
[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     if ( url.pathname.split( "/" ).splice(-1)[0] === "search" ) {
8         exec( "notmuch search " + url.query, function( error, stdout, stderr ) {
9             res.writeHead( 200, { "Content-Type": "text/plain" } );
10             res.end( stdout );    
11         });
12     } else {
13         res.writeHead( 404 );
14         res.end("404");
15     }
16 }).listen( 8124, "127.0.0.1" );
17
18 console.log( "Server running at http://127.0.0.1:8124/" );