gravity.js
function getResource(map, base, internal, path, callback, addLineHints) {
		var
			reduced = reduce(map, path),
			reducedMap = reduced.map,
			reducedMapType = nodeType(reducedMap),
			reducedPrefix = reduced.prefix,
			reducedSuffix = reduced.suffix,
			firstChar = path.charAt(0),
			temporary = firstChar === '~',
			literal = firstChar === '='
		;

		if (isURL(path)) {
			wget(path, callback);

		} else if (literal) {
			callback(null, new Buffer(path.substr(1) + '\n'));

		} else if (temporary && !internal) {
			// External request for a temporary resource.
			callback({ code: 403, message: 'Forbidden' });

		} else if (reducedSuffix) {
			// We did NOT find an exact match in the map.

			if (!reducedPrefix && internal) {
				getFile(base, path, callback, addLineHints);
			} else if (reducedMapType === 'string') {
				getFile(base, reducedMap + '/' + reducedSuffix, callback, addLineHints);
			} else {
				callback({ code: 404, message: 'Not Found' });
			}

		} else {
			// We found an exact match in the map.

			if (reducedMap === reducedPrefix) {
				// This is just a local file/dir to expose.
				getFile(base, reducedPrefix, callback, addLineHints);

			} else if (reducedMapType === 'string') {
				// A string value may be a web URL.
				if (isURL(reducedMap)) {
					wget(reducedMap, callback);
				} else {
					// Otherwise, it's another resource path.
					getResource(map, base, true, reducedMap, callback, addLineHints);
				}

			} else if (reducedMapType === 'array') {
				// An array is a list of resources to get packed together.
				packResources(map, base, reducedMap, callback);

			//} else if (reducedMapType === 'object') {
				// An object is a directory. We could return a listing...
				// TODO: Do we really want to support listings?

			} else {
				callback({ code: 500, message: 'Unable to read gravity.map.' });
			}
		}
	}
function getResource(map, base, internal, path, callback, addLineHints) {
		var
			reduced = reduce(map, path),
			reducedMap = reduced.map,
			reducedMapType = nodeType(reducedMap),
			reducedPrefix = reduced.prefix,
			reducedSuffix = reduced.suffix,
			firstChar = path.charAt(0),
			temporary = firstChar === '~',
			literal = firstChar === '='
		;

		if (isURL(path)) {
			wget(path, callback);

		} else if (literal) {
			callback(null, new Buffer(path.substr(1) + '\n'));

		} else if (temporary && !internal) {
			// External request for a temporary resource.
			callback({ code: 403, message: 'Forbidden' });

		} else if (reducedSuffix) {
			// We did NOT find an exact match in the map.

			if (!reducedPrefix && internal) {
				getFile(base, path, callback, addLineHints);
			} else if (reducedMapType === 'string') {
				getFile(base, reducedMap + '/' + reducedSuffix, callback, addLineHints);
			} else {
				callback({ code: 404, message: 'Not Found' });
			}

		} else {
			// We found an exact match in the map.

			if (reducedMap === reducedPrefix) {
				// This is just a local file/dir to expose.
				getFile(base, reducedPrefix, callback, addLineHints);

			} else if (reducedMapType === 'string') {
				// A string value may be a web URL.
				if (isURL(reducedMap)) {
					wget(reducedMap, callback);
				} else {
					// Otherwise, it's another resource path.
					getResource(map, base, true, reducedMap, callback, addLineHints);
				}

			} else if (reducedMapType === 'array') {
				// An array is a list of resources to get packed together.
				packResources(map, base, reducedMap, callback);

			//} else if (reducedMapType === 'object') {
				// An object is a directory. We could return a listing...
				// TODO: Do we really want to support listings?

			} else {
				callback({ code: 500, message: 'Unable to read gravity.map.' });
			}
		}
	}
function getResource ( map , base , internal , path , callback , addLineHints ) { var reduced = reduce ( map , path ) , reducedMap = reduced . map , reducedMapType = nodeType ( reducedMap ) , reducedPrefix = reduced . prefix , reducedSuffix = reduced . suffix , firstChar = path . charAt ( 0 ) , temporary = firstChar === '~' , literal = firstChar === '=' ; if ( isURL ( path ) ) { wget ( path , callback ) ; } else if ( literal ) { callback ( null , new Buffer ( path . substr ( 1 ) + '\n' ) ) ; } else if ( temporary && ! internal ) { // External request for a temporary resource. callback ( { code : 403 , message : 'Forbidden' } ) ; } else if ( reducedSuffix ) { // We did NOT find an exact match in the map. if ( ! reducedPrefix && internal ) { getFile ( base , path , callback , addLineHints ) ; } else if ( reducedMapType === 'string' ) { getFile ( base , reducedMap + '/' + reducedSuffix , callback , addLineHints ) ; } else { callback ( { code : 404 , message : 'Not Found' } ) ; } } else { // We found an exact match in the map. if ( reducedMap === reducedPrefix ) { // This is just a local file/dir to expose. getFile ( base , reducedPrefix , callback , addLineHints ) ; } else if ( reducedMapType === 'string' ) { // A string value may be a web URL. if ( isURL ( reducedMap ) ) { wget ( reducedMap , callback ) ; } else { // Otherwise, it's another resource path. getResource ( map , base , true , reducedMap , callback , addLineHints ) ; } } else if ( reducedMapType === 'array' ) { // An array is a list of resources to get packed together. packResources ( map , base , reducedMap , callback ) ; //} else if (reducedMapType === 'object') { // An object is a directory. We could return a listing... // TODO: Do we really want to support listings? } else { callback ( { code : 500 , message : 'Unable to read gravity.map.' } ) ; } } }
Given a resource path, retrieve the associated content.  Internal requests are always allowed, whereas external requests will only have access to resources explicitly exposed by the gravity map.
Given a resource path retrieve the associated content . Internal requests are always allowed whereas external requests will only have access to resources explicitly exposed by the gravity map .