lib/sampler/sampler.js
function requestResponseHandler(req, res, path) {
	if (panoptica.length === 0) {
		// not set up

		res.writeHead(500, { 'content-type': 'text/plain' });
		res.end('Sampler has not been configured with any intervals');
		return;
	}

	var queryPath;

	try {
		queryPath = pathToQuery(path);
	} catch (error) {
		// bad request
		res.writeHead(400, { 'content-type': 'text/plain' });
		res.end('Failed to parse query path: ' + path);
		return;
	}

	var data = exports.query(queryPath);

	if (data === undefined) {
		logger.verbose('Could not find path', queryPath, 'in sampler. Available:', Object.keys(gatheredData));

		res.writeHead(404, { 'content-type': 'text/plain' });
		res.end('There is no data available at "' + queryPath.join('/') + '" at this time.');
		return;
	}

	try {
		data = JSON.stringify(data, null, '  ');
	} catch (jsonError) {
		logger.error('Error serializing sampler data:', jsonError);

		res.writeHead(500, { 'content-type': 'text/plain' });
		res.end('Error while serializing data');
		return;
	}

	res.writeHead(200, { 'content-type': 'application/json' });
	res.end(data);
}
function requestResponseHandler(req, res, path) {
	if (panoptica.length === 0) {
		// not set up

		res.writeHead(500, { 'content-type': 'text/plain' });
		res.end('Sampler has not been configured with any intervals');
		return;
	}

	var queryPath;

	try {
		queryPath = pathToQuery(path);
	} catch (error) {
		// bad request
		res.writeHead(400, { 'content-type': 'text/plain' });
		res.end('Failed to parse query path: ' + path);
		return;
	}

	var data = exports.query(queryPath);

	if (data === undefined) {
		logger.verbose('Could not find path', queryPath, 'in sampler. Available:', Object.keys(gatheredData));

		res.writeHead(404, { 'content-type': 'text/plain' });
		res.end('There is no data available at "' + queryPath.join('/') + '" at this time.');
		return;
	}

	try {
		data = JSON.stringify(data, null, '  ');
	} catch (jsonError) {
		logger.error('Error serializing sampler data:', jsonError);

		res.writeHead(500, { 'content-type': 'text/plain' });
		res.end('Error while serializing data');
		return;
	}

	res.writeHead(200, { 'content-type': 'application/json' });
	res.end(data);
}
function requestResponseHandler ( req , res , path ) { if ( panoptica . length === 0 ) { // not set up res . writeHead ( 500 , { 'content-type' : 'text/plain' } ) ; res . end ( 'Sampler has not been configured with any intervals' ) ; return ; } var queryPath ; try { queryPath = pathToQuery ( path ) ; } catch ( error ) { // bad request res . writeHead ( 400 , { 'content-type' : 'text/plain' } ) ; res . end ( 'Failed to parse query path: ' + path ) ; return ; } var data = exports . query ( queryPath ) ; if ( data === undefined ) { logger . verbose ( 'Could not find path' , queryPath , 'in sampler. Available:' , Object . keys ( gatheredData ) ) ; res . writeHead ( 404 , { 'content-type' : 'text/plain' } ) ; res . end ( 'There is no data available at "' + queryPath . join ( '/' ) + '" at this time.' ) ; return ; } try { data = JSON . stringify ( data , null , '  ' ) ; } catch ( jsonError ) { logger . error ( 'Error serializing sampler data:' , jsonError ) ; res . writeHead ( 500 , { 'content-type' : 'text/plain' } ) ; res . end ( 'Error while serializing data' ) ; return ; } res . writeHead ( 200 , { 'content-type' : 'application/json' } ) ; res . end ( data ) ; }
A simple HTTP request-response handler to wrap exports.query.

@param {http.ClientRequest}  req  HTTP client request object.
@param {http.ServerResponse} res  HTTP server response object.
@param {string}              path The path in the URL.
A simple HTTP request - response handler to wrap exports . query .