lib/json_mason/json_mason.js
/**
 * Routes requests and sets initial variables.
 */
Routes requests and sets initial variables.
Routes requests and sets initial variables .
function route(req, res) {
  var req_obj = {
    request: req,
    response: res,
    url: url.parse(req.url, true),
    get_arguments: {},
    url_arguments: []
  }
  req_obj.get_arguments = req_obj.url.query;
  var path = req_obj.url.pathname;
  for (var i in ROUTES) {
    var route = ROUTES[i];
    if ('url' in route && route.url == path) {
      return handle_reponse(res, route.callback(req_obj));
    } else if ('pattern' in route && route.pattern.test(path)) {
      req_obj.url_arguments = route.pattern.exec(path);
      return handle_reponse(res, route.callback(req_obj));
    }
  }
  send_response_string(res, 404, "404/Not found.");
}
function route ( req , res ) { var req_obj = { request : req , response : res , url : url . parse ( req . url , true ) , get_arguments : { } , url_arguments : [ ] } req_obj . get_arguments = req_obj . url . query ; var path = req_obj . url . pathname ; for ( var i in ROUTES ) { var route = ROUTES [ i ] ; if ( 'url' in route && route . url == path ) { return handle_reponse ( res , route . callback ( req_obj ) ) ; } else if ( 'pattern' in route && route . pattern . test ( path ) ) { req_obj . url_arguments = route . pattern . exec ( path ) ; return handle_reponse ( res , route . callback ( req_obj ) ) ; } } send_response_string ( res , 404 , "404/Not found." ) ; }
Routes requests and sets initial variables.
Routes requests and sets initial variables .