-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Reference configuration of app.js
In pomelo there are two app.js, one is in the game-server directory and the other is in web-server directory.They are corresponding to the game server and the web server, and each of them is server's entry. The following app.js configuration reference is just for game server.
The app.js is the entrance of pomelo project.When using the pomelo command line to create a new project, a default app.js file will be generated according to the basic information of the project. Its main content is as follows:
var pomelo = require('pomelo');
var app = pomelo.createApp();
app.set('name', 'nameofproject');
app.set('dirname', __dirname);
app.defaultConfiguration();
app.start();Application variables can be accessed through the set and get methods, for example, to access the server object, and the specific code as follows:
app.set('server',server);
var server = app.get('server');Application states information can be activated and inactivated by the enable and disable methods, for example, you want to activate or inactivate application's schedulerService state.Also, the user can use enabled and disabled methods to judge whether the state exists, if exists returns true, otherwise returns false. Specific code as follows:
app.enable('filter');
app.enabled('filter'); //返回true
app.disable('filter');
app.disabled('filter'); //返回trueUsers can load configuration files and services through loadConfig and loadService methods, after loading the file parameters will be mounted directly to the application object. For example to load mysql.json file, the specific code as follows:
{
"development":
{
"host":"127.0.0.1",
"port":"3306",
"database":"pomelo"
}
}app.loadConfig('mysql.json');
var host = app.mysql.host; //返回 127.0.0.1
app.loadService('scheduleService');The server configuration is mainly done by the configure () method, a complete app.configure configuration parameters are as follows:
app.configure([env], [serverType], [function]);The first two parameters are optional, the following parameter description:
- env: Runtime environment, can be set to development, production or development | production.
- serverType: Server type, if set this parameter only do initialization on this type of server, otherwise all servers perform initialization function.
- function: The specific initialization operation, the internal can contain any js method.
Some configuration examples are as follows:
app.configure(function(){
});This configuration will bring all servers under all modes (development / production) into effect.
app.configure('development', function(){
});This configuration will only bring all servers under a fixed mode into effect.
app.configure('development', 'chat', function(){
});This configuration will only bring chat servers under development mode into effect.
Users can make different configurations for different servers according to various demands of the application, for example to configure the startup file of mysql in the global
app.configure('development|production', function(){
app.set('mysql', app.get('dirname')+'/config/mysql.json');
});Furthermore you can make configurations on a specific server, such as:
var initArea = function(){
//area init
};
app.configure('development|production', 'area', function(){
initArea();
});Each component has a life cycle, and it is usually loaded during the initialization of application. The components of pomelo are as follows: master, monitor, filter, proxy, handler, remote, server, sync and connection, and their main function are as follows: