First function, that runs in router
8038
public function run($URL,$host=''){
		if(ROUTER_DEBUG){
			BLog::addToLog('[Router]: Router started! URL='.$URL.'; host='.$host);
			}
		$this->init();
		//bimport('ip.ban');
		//$r=BIpBan::check();
		//if($r===false){
		//	header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
		//	return $this->errorpage('ipban');
		//	}
		$this->url=$URL;
		$this->host=$host;

		$r=$this->parseurl($URL,$host);

		if(ROUTER_DEBUG){
			if($r){
				BLog::addToLog('[Router]: Rules successfully parsed.');
				}else{
				BLog::addToLog('[Router]: Error of parsing rules!',LL_ERROR);
				}
			}
		if($r===false){
			header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
			header('Content-type: text/html; charset=utf-8');
			return $this->errorpage('404');
			}
		if(ROUTER_DEBUG){
			BLog::addToLog('[Router]: rules:'.var_export($this->rules,true));
			}
		$this->render_positions();
		switch($this->ctype){
			case CTYPE_HTML:
				$this->generatepage_html();
				break;
			case CTYPE_PLAINHTML:
				$this->generatepage_plainhtml();
				break;
			case CTYPE_JSON:
				$this->generatepage_json();
				break;
			case CTYPE_XML:
				$this->generatepage_xml();
				break;
			case CTYPE_DOCX:
				$this->generatepage_docx();
				break;
			case CTYPE_CSV:
				$this->generatepage_csv();
				break;
			case CTYPE_PDF:
				$this->generatepage_pdf();
				break;
			case CTYPE_REDIRECT301:
				$this->redirect301($this->redirectURL);
				break;
			case CTYPE_REDIRECT302:
				$this->redirect302($this->redirectURL);
				break;
			default:
				echo('Unknown content type!');
				break;
			}
		}
75424
function (app, next) {
      app.use(function (req, res, next) {
        router.handle(req, res, next);
      });

      next(null, app);
    }
279018
static private function _registerDispatch() {
        // Register dispatch function
        $auto_dispatch = !is_null(Config::get('router.auto_dispatch')) ?
            Config::get('router.auto_dispatch') :
            true;
        
        if (!self::$_dispatch_registered && $auto_dispatch) {
            // Make sure things ends here...
            register_shutdown_function(function() {
                // Get response data from Dispatcher
                $response = self::dispatch();
            });
            
            // Mark as dispatched
            self::$_dispatch_registered = true;
        }
    }
390817
function init (prefs, callback) {
	options = _.extend(defaults, prefs);
	app = options.app || express();
	app.use(cors());

	ramlMocker.generate(options, process(function(requestsToMock){
		requestsToMock.forEach(function(reqToMock){
			addRoute(reqToMock);
		});
		log(new Array(30).join('='));
		log('%s[%s]%s API routes generated', colors.qyan, requestsToMock.length, colors.default);

		if(typeof callback === 'function'){
			callback(app);
		}
	}));

	var watcher = watch();
	var server = launchServer(app);

	function close () {
		if (watcher) { watcher.close(); }
		if (server) { server.close(); }
	}

	return {
		close: close,
		server: server,
		watcher: watcher
	};
}
145870
function(name){
		var routerCfg = config.router.instances[name];
		log("debug", "Instantiating Router - " + name);
		routers[name] = new EventEmitter2({wildcard: true, delimiter: '.', newListener: false, maxListeners:  config.maxObjectListeners, verboseMemoryLeak: false});
		var Incoming = function(message){
			var route = Route(message.request.host, message.request.path);
			var verb = message.request.verb.toLowerCase();
			if(!route || !route.match.controller) { 
				log("warning","Router > Received request from an interface but could not resolve endpoint - 404 - " + message.msgId, message);
				ReturnError(message,"Page Not Found",404); 
				return; 
			}
			var controller = route.match.controller;
			var Req = require("./lib/req.js");
			var req = new Req;
			req.init(isnode, {
				msgId: message.msgId,
				type: message.type,
				interface: message.interface,
				router: name,
				path: message.request.path,
				host: message.request.host,
				headers: message.request.headers,
				port: message.request.port,
				query: message.request.query,
				params: route.param,
				cookies: message.request.cookies,
				ip: message.request.ip,
				verb: message.request.verb,
				secure: message.request.secure,
				service: route.match.service,
				body: message.request.body
			});
			var Res = require("./lib/res.js");
			var res = new Res;
			res.init(isnode, {
				msgId: message.msgId,
				service: route.match.service,
				type: message.type,
				interface: message.interface,
				router: name
			});
			var responseListener = function(msg){
				log("debug","Router > Received response from controller. Message ID: " + message.msgId, message);
				isnode.module(message.type, "interface").get(message.interface).emit("outgoing."+message.msgId,msg);
				routers[name].removeListener('router.' + msg.msgId, responseListener);
			}
			routers[name].on('router.' + message.msgId, responseListener);
			var verbs = ["get", "post", "put", "delete", "update", "patch", "head", "options", "trace"];
			if(message.request.verb && controller && controller[verb] && verbs.includes(verb)) {
				controller[verb](req,res);
			} else {
				log("error","Router > Cannot pass control to controller because controller function cannot be found", message);
			}
		}
		var Route = function(hostname,url){
			var searchObj = {
				hostname: hostname,
				url: url,
				services: config.router.instances[name].services
			}
			return isnode.module("services").search(searchObj);
		}
		var ReturnError = function(msgObject,message,statusCode){
			var msg = {
				"type": msgObject.type,
				"interface": msgObject.interface,
				"msgId": msgObject.msgId,
				"sessionId": msgObject.sessionId,
				"state": "outgoing",
				"directional": msgObject.directional,
				"response": {
					"body": {"message":message},
					"message": message,
					"statusCode": statusCode
				}
			}	
			log("debug","Router > Sending message " + msgObject.msgId + " back to originating interface", msgObject);
			if(msgObject.sessionId)
				isnode.module(msgObject.type, "interface").get(msgObject.interface).emit("outgoing."+msgObject.sessionId,msg);
			else
				isnode.module(msgObject.type, "interface").get(msgObject.interface).emit("outgoing."+msgObject.msgId,msg);
			return;
		}
		routers[name].incoming = Incoming;
		routers[name].route = Route;
		return;
	}
423606
function Router(socket, options) {
  stream.Transform.call(this, { objectMode: true });

  this.options = merge(Object.create(Router.DEFAULTS), options || {});
  this.socket = socket;
}
173594
function router(req, resp, next) {
    const routerPath = req.routePath || '';

    const beforeRunMiddleware = (route) => {
      const match = matchRoute(routerPath, req, route);
      if (!match) return false;

      const { params, path: matchPath } = match;

      if (options.params) req.params = { ...options.params, ...params };
      else req.params = params;

      // dynamically set req.routePath for the route
      req.routePath = routerPath + matchPath;
      return true;
    };
    const routeStack = compose(router.routes, { beforeRunMiddleware });

    return routeStack.call(this, req, resp, () => {
      req.routePath = routerPath;// restore routePath
      return next && next();
    });
  }
1034634
function buildRoutes(router, apiOrBuilder) {
    // if it's a builder function, build it...
    let pathPrefix = null;
    let api = null;
    let registry = null;
    let instanceName = null;
    if (_.isObject(apiOrBuilder)) {
        pathPrefix = apiOrBuilder.path;
        api = apiOrBuilder.api;
        registry = apiOrBuilder.registry;
        instanceName = apiOrBuilder.instanceName;
    } else {
        api = apiOrBuilder;
    }

    if (_.isFunction(api)) {
        api = api();
    }

    if (!registry && _.isFunction(api.registry)) {
        registry = api.registry();
    }

    if (!registry) {
        // print errors here
        return;
    }

    _.forEach(registry, (value, key) => {
        if (_.isArray(value)) {
            _.forEach(value, item => buildRoute(router, api, key, item, pathPrefix, instanceName));
        } else {
            buildRoute(router, api, key, value, pathPrefix, instanceName);
        }
    });
}
731499
function RouterStateSnapshot(url, root) {
        _super.call(this, root);
        this.url = url;
        setRouterStateSnapshot(this, root);
    }
820060
function (method, endpoint, routerMiddelware) {
		var self = this;

		if (typeof routerMiddelware == 'object'){
			this.app[method](endpoint, function (req, res, next) {
				var middlewareFunction = []
				routerMiddelware.forEach(function (m) {
					middlewareFunction.push(function (cb) {
						self.__exec__middlewares(m, req, res, cb);
					});
				});

				async.waterfall(middlewareFunction);
			});
		} else {
			this.app[method](endpoint, function (req, res, next) {
				self.__exec__middleware(routerMiddelware)(req, res, next);
			});
		}
	}
500640
public RouterLike CONNECT_FIRST(String path, T target) {
    return patternFirst(CONNECT(), path, target);
  }
756673
function(req, res, router, cb) {
  var url = (req.url === '/') ? '/' + router.defaultPage : req.url;
  var source = router.static.path + url; //path.resolve(router.static.path, '.'+url);
  if (url.indexOf('.') != -1) {
    router.stat(source, function(err, stat) {
      if (err || stat === undefined || stat.size === undefined) {
        cb();
      } else {
        res.writeHead(200, {
          'Content-Type': router.getMime(url),
          'Content-Length': stat.size
        });
        router.openStream(source).pipe(res);
      }
    });
  } else {
    cb();
  }
}
349617
function run(route, index, path, query, res, next) {
    mm.create(route.action).then(
        function (presenter) {
            var ele = new Element('div');

            function finish() {
                var model = presenter.model;
                res.html = ele.outerHTML;
                res.data = model.store;
                res.routeIndex = index;
                next();
            }

            presenter
                .enter(ele, path, query)
                .then(finish, next);
        },
        next
    ).then(null, next);
}
93287
function initGetList(router, adminCGIBase, pluginName, callback) {
    router.get(`${adminCGIBase}/${pluginName}`, callback);
}
380290
function run(params, command, callback)
{
  var terminator
    , requiresContext = isArrowFunction(command)
    ;

  // make sure callback is invoked in real async way
  callback = async(callback);

  // check provided function if it expected
  // to be run in async or sync way

  // expects no arguments, run it as sync function
  // unless it's function straight outta factory
  // has `.commandDescription` property
  //
  // Or it has one argument and requires context
  // must be arrow function with `context` argument
  if ((command.length === 0 || (command.length === 1 && requiresContext)) && !command.commandDescription)
  {
    runSync(this, command, callback);
  }
  else // or run it as async
  {
    // async function may return terminator function
    terminator = runAsync(this, command, callback);
  }

  // return provided terminator or empty function
  // if there is none
  return terminator || function() {};
}
557051
def run_with_router(func, *args, **kwargs):
    
    broker = mitogen.master.Broker()
    router = mitogen.master.Router(broker)
    try:
        return func(router, *args, **kwargs)
    finally:
        broker.shutdown()
        broker.join()
1346104
function routerMiddleware(history) {
  return function () {
    return function (next) {
      return function (action) {
        if (action.type !== _actions.CALL_HISTORY_METHOD) {
          return next(action);
        }

        var _action$payload = action.payload,
            method = _action$payload.method,
            args = _action$payload.args;

        history[method].apply(history, _toConsumableArray(args));
      };
    };
  };
}