public function run($app)
    {
        if (!$app->request->getIsConsoleRequest()) {
            if ($this->hasModule('admin') && $app->request->isAdmin) {
                // When admin context, change csrf token, this will not terminate the frontend csrf token:
                // @see https://github.com/luyadev/luya/issues/1778
                $app->request->csrfParam = '_csrf_admin';
                
                foreach ($this->getModules() as $id => $module) {
                    if ($module instanceof AdminModuleInterface) {
                        $this->_adminAssets = ArrayHelper::merge($module->getAdminAssets(), $this->_adminAssets);
                        if ($module->getMenu()) {
                            $this->_adminMenus[$module->id] = $module->getMenu();
                        }
                        $this->_jsTranslations[$id] = $module->getJsTranslationMessages();
                    }
                }
                
                $app->getModule('admin')->assets = $this->_adminAssets;
                $app->getModule('admin')->controllerMap = $this->_apis;
                $app->getModule('admin')->moduleMenus = $this->_adminMenus;
                $app->getModule('admin')->setJsTranslations($this->_jsTranslations);
                
                // calculate api defintions
                if ($app->getModule('admin')->hasProperty('apiDefintions')) { // ensure backwards compatibility
                    $app->getModule('admin')->apiDefintions = $this->generateApiRuleDefintions($this->_apis, $this->_apiRules);
                }
                // as the admin module needs to listen for $apiDefintions we have to get the urlRules from the admin and merge with the existing rules:
                // in admin context, admin url rules have always precedence over frontend rules.
                $this->_urlRules = array_merge($app->getModule('admin')->urlRules, $this->_urlRules);
            }
        }
        
        $app->getUrlManager()->addRules($this->_urlRules);
    }