anchor.diff:                      false -> ok
                   end,
                   
  -                if
  -                    IsMasterNode ->
  -                        case boss_env:get_env(server, ?DEFAULT_WEB_SERVER) of
  -                            cowboy ->
  -                                WebSocketModules = boss_files:websocket_list(AppName),
  -                                MappingServices  = boss_files:websocket_mapping(BaseURL,
  -                                    atom_to_list(AppName),
  -                                    WebSocketModules),
  -                                boss_service_sup:start_services(ServicesSupPid, MappingServices);
  -                            _Any ->
  -                                _Any
  -                        end;
  -                    true ->
  -                        ok
  -                end,
  +                enable_master_apps(ServicesSupPid, AppName, BaseURL,
  +                                   IsMasterNode),
                   
  -                InitData = run_init_scripts(AppName),
  -                #boss_app_info{ application = AppName,
  -                    init_data = InitData,
  -                    router_sup_pid = RouterSupPid,
  -                    translator_sup_pid = TranslatorSupPid,
  -                    base_url = (if BaseURL =:= "/" -> ""; true -> BaseURL end),
  -                    static_prefix = StaticPrefix,
  -                    doc_prefix = DocPrefix,
  -                    domains = DomainList,
  -                    model_modules = ModelList,
  -                    view_modules = ViewList,
  -                    controller_modules = ControllerList
  -                }
  -        end, Applications),
  +                make_boss_app_info(AppName, BaseURL, StaticPrefix, DocPrefix,
  +                                   DomainList, ModelList, ViewList,
  +				   ControllerList, RouterSupPid,
  +				   TranslatorSupPid)
  +				    end, Applications),
   
       %% cowboy dispatch rule for static content
       case boss_env:get_env(server, ?DEFAULT_WEB_SERVER) of
  
positive.code:             error_logger:info_msg("Pinging master node ~p from ~p~n", [MasterNode, ThisNode]),
              pong = net_adm:ping(MasterNode)
      end,
  
      MailDriver = boss_env:get_env(mail_driver, boss_mail_driver_smtp),
      boss_mail:start([{driver, MailDriver}]),
  
      {ServerMod, RequestMod, ResponseMod} = case boss_env:get_env(server, ?DEFAULT_WEB_SERVER) of
          mochiweb -> {mochiweb_http, mochiweb_request_bridge, mochiweb_response_bridge};
          cowboy -> {cowboy, mochiweb_request_bridge, mochiweb_response_bridge}
      end,
      SSLEnable = boss_env:get_env(ssl_enable, false),
      SSLOptions = boss_env:get_env(ssl_options, []),
      error_logger:info_msg("SSL:~p~n", [SSLOptions]),
  
      {ok, ServicesSupPid}  = case MasterNode of
  				ThisNode ->
  				    boss_service_sup:start_link();
  				_AnyNode ->
  				    {ok, undefined}
  			    end,
  
      ServerConfig = [{loop, fun(Req) ->
                      ?MODULE:handle_request(Req, RequestMod, ResponseMod)
              end} | Config],
      Pid = case ServerMod of
          mochiweb_http ->
              application:start(mochiweb),
              mochiweb_http:start([{ssl, SSLEnable}, {ssl_opts, SSLOptions} | ServerConfig]);
          cowboy ->
  		  %Dispatch = [{'_', [{'_', boss_mochicow_handler, [{loop, {boss_mochicow_handler, loop}}]}]}],
  		  error_logger:info_msg("Starting cowboy... on ~p~n", [MasterNode]),
  		  application:start(ranch),
  		  application:start(cowboy),
  		  HttpPort = boss_env:get_env(port, 8001),
            AcceptorCount = boss_env:get_env(acceptor_processes, 100),
            case SSLEnable of
                false ->
                    error_logger:info_msg("Starting http listener... on ~p ~n", [HttpPort]),
                    cowboy:start_http(boss_http_listener, AcceptorCount, [{port, HttpPort}], [{env, []}]);
                true ->
                    error_logger:info_msg("Starting https listener... on ~p ~n", [HttpPort]),
                    SSLConfig = [{port, HttpPort}]++SSLOptions,
                    cowboy:start_https(boss_https_listener, AcceptorCount, SSLConfig, [{env, []}])
  		  end,
  		  if
                MasterNode =:= ThisNode ->
                    boss_service_sup:start_services(ServicesSupPid, boss_websocket_router);
                true ->
                    ok
  		  end
  
  	  end,
      {ok, #state{ service_sup_pid = ServicesSupPid, http_pid = Pid, is_master_node = (ThisNode =:= MasterNode) }, 0}.
  
  handle_info(timeout, State) ->
      Applications = boss_env:get_env(applications, []),
      ServicesSupPid = State#state.service_sup_pid,
      AppInfoList = lists:map(fun
              (AppName) ->
                  application:start(AppName),
                  BaseURL = boss_env:get_env(AppName, base_url, "/"),
                  StaticPrefix = boss_env:get_env(AppName, static_prefix, "/static"),
                  DocPrefix = boss_env:get_env(AppName, doc_prefix, "/doc"),
                  DomainList = boss_env:get_env(AppName, domains, all),
                  ModelList = boss_files:model_list(AppName),
                  ViewList = boss_files:view_module_list(AppName),
                  IsMasterNode = boss_env:is_master_node(),
                  ControllerList = boss_files:web_controller_list(AppName),
                  {ok, RouterSupPid} = boss_router:start([{application, AppName},
                          {Controllers, ControllerList}]),
                  {ok, TranslatorSupPid} = boss_translator:start([{application, AppName}]),
                  case boss_env:is_developing_app(AppName) of
  
negative.code: -define(DEFAULT_WEB_SERVER, cowboy).
  
  -record(state, {
          applications	= [],
          service_sup_pid,
          http_pid,
          smtp_pid,
          is_master_node	= false
      }).
  
  -include("boss_web.hrl").
  
  start_link() ->
      init_master_node().
  
  init_master_node() -> start_link([]).
  
  start_link(Config) ->
      gen_server:start_link({local, boss_web}, ?MODULE, Config, []).
  