Here is the chunk of code for this discussion...
var ServerCallback = function( request, result )
{
var urlData = url.parse( request.url );
if( urlData.pathname === '/' )
{
var htmlPage = fs.readFileSync( 'CheckersLobby.html', 'utf8' );
var JsdomCallback = function( errors, window )
{
var $ = window.$;
$( 'h1' ).text( 'Blah!' );
htmlPage = window.document.documentElement.outerHTML;
result.writeHead( 200, { 'Content-type' : 'text/html' } );
result.end( htmlPage );
}
// Note that the following call returns before the given callback is called, so we
// return from this callback without responding to the request. However, the
// callback eventually gets called and is still able to respond to the request.
// I'm not sure exactly what is going on here, or why this works.
}
else
{
result.writeHead( 404, { 'Content-Type' : 'text/plain' } );
result.end( 'Page not found!\n' );
}
}
var server = http.createServer( ServerCallback );