var http = require('http');
var express = require('express');
var app = express();
var setttings=require("./app/config/settings");
var environment = require('./app/config/environment');
// var SocketServer=require("./app/config/socket.server");
//const cluster = require('cluster');
//const numCPUs = require('os').cpus().length;
// all environments
environment(app);//初始化环境
// 错误处理中间件应当在路由加载之后才能加载
// if (cluster.isMaster) {
//   console.log(`Master ${process.pid} is running`);
//
//   // Fork workers.
//   for (let i = 0; i < numCPUs; i++) {
//     cluster.fork();
//   }
//   cluster.on('exit', (worker, code, signal) => {
//     console.log(`worker ${worker.process.pid} died`);
//   });
// }else{
//   var server = http.createServer(app);
//   var socketServer = new SocketServer(server);
//   server.listen(setttings.port, function(){
//     console.log('Express server listening on port ' + app.get('port'));
//   });
// }
let log4js = require('log4js');
let logger = log4js.getLogger();
logger.level = "all";
console.log=logger.info.bind(logger);
console.error=logger.error.bind(logger);

var server = http.createServer(app);
//var socketServer = new SocketServer(server);
server.listen(setttings.port, function(){
  console.log('Express server listening on port ' + app.get('port'));
  console.log('apidoc address ' +`http://localhost:${app.get('port')}/apidoc/index.html`);
});

