代码拉取完成,页面将自动刷新
/*!
* 服务启动脚本
*/
CHANNEL_WEB = "web";
var express = require("express")
, app = module.exports = express()
, util = require("util")
, bodyParser = require("body-parser")
, methodOverride = require('method-override')
, errorhandler = require('errorhandler')
, cookieParser = require("cookie-parser")
, redis = require("redis")
// 解释表单数据
, multipart = require("connect-multiparty")
, session = require("express-session")
, RedisStore = require('connect-redis')(session)
, router = require("./server/routes")
;
// 全局变量
sformat = require("./server/lib/string-format");
socketAction = require("./server/routes/socketio");
config = require("./server/config");
// Redis Client
redisConfig = {filters:[]}; //redisClient.get("console_watcher_config")||{};
redisClient = redis.createClient( config["redisPort"], config["redisHost"] );
redisClient.on('connect', function(){
redisClient.select(config["redisDatabase"]||0);
});
redisClient.on('error', function(err){
console.error(err);
});
// 订阅console消息
subscriber = redis.createClient( config["redisPort"], config["redisHost"] );
// subscriber.on('connect', function(){
// subscriber.select(config["redisDatabase"]||0);
// });
subscriber.on('error', function(err){
console.error(err);
});
subscriber.on("message", socketAction.onConsoleMessage );
subscriber.subscribe( "console-log" );
subscriber.subscribe( "console-server-reg");
// 设置视图目录
app.set('views', __dirname + '/server/views');
// 设置模板引擎
var vash = require("vash");
vash.config.modelName = "t";
vash.config.debug = true;
// 模板文件后缀使用.html
app.engine(".html", vash.__express );
app.set('view engine', 'html');
app.set("trust proxy", true);
// APP 挂件
// ---------
// 设置表态目录
// static 为关键字, 故使用 express['static']
app.use( express.static( __dirname + '/server/public') );
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json());
// override with the X-HTTP-Method-Override header in the request
app.use( methodOverride('X-HTTP-Method-Override') );
app.use( cookieParser() );
app.use(function(req, res, next){
next();
});
//Redis
app.use(session({
resave: true,
secret:'keyboard cat',
saveUninitialized: false,
cookie: { secure: true },
store: new RedisStore({
host: "RedisServer",
port: "6379",
db: 2 // redis 数据库
}),
name: 'esid'
}));
app.use(errorhandler({ dumpExceptions: true, showStack: true }));
app.get("/",function(req,res){
res.send("Access Forbidden!");
});
app.get("/clientip", router.clientip);
app.get("/watcher", router.watcher );
//app.post("/gather", multipart(), router.gather );
var server = app.listen(config.port,function(){
var host = server.address().address
var port = server.address().port
console.log('WatcherServer listening at http://%s:%s', host, port)
})
// globals
io = require("socket.io").listen(server);
io.gather = {
threads:{}
};
// When someone connects to the websocket. Includes all the SocketIO events.
io.sockets.on('connection', socketAction.SocketOnConnection);
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。