/** * TODO license * Router class. */ var util = require('util') Endpoint = require('../endpoint/endpoint.js'), Outputter = require('../outputter/outputter'); exports = module.exports = Router; function Router() { // constructor } Router.prototype = { // // FUNCTIONS // /** * Build the endpoint for given path. * @param path full path * @param callback callback */ buildEndpoint : function (path, callback) { logger.debug('Building endpoint for ' + path); var endpoint = null; var error = null; if (!config.endpoints) { error = new Error("no endpoints defined"); } else { var match = PATH_RE.exec(path); var resName = match ? match[1] : null; logger.debug('Match resource : ' + resName); var resModule = config.endpoints[resName]; if (resModule) { logger.debug('Loading ' + resModule); try { logger.debug('../' + resModule); endpoint = require('../' + resModule); } catch (err) { logger.debug('Error loading module'); error = err; } } else { error = new Error('No module for ' + resName); } } callback(error, endpoint); }, /** * Build an outputter for given mime type. * @param mime requested mime type. * @param callback error callback */ buildOutputter : function(mime, callback) { var mimes = mime.split(','); var outputter = null; for (var i=0; i