@@ -8,6 +8,7 @@ var path = require('path');
88var fs = require ( 'fs' ) ;
99const http = require ( 'http' ) ;
1010const https = require ( 'https' ) ;
11+ const redisCli = require ( './redis' ) ;
1112
1213var privateKey = fs . readFileSync ( path . join ( __dirname , './certificate/private.key' ) , 'utf8' ) ;
1314var certificate = fs . readFileSync ( path . join ( __dirname , './certificate/file.crt' ) , 'utf8' ) ;
@@ -32,6 +33,7 @@ httpsServer.listen(SSLPORT, function () {
3233
3334
3435var mooc = new moocModel ( ) ;
36+ var redis = new redisCli ( ) ;
3537
3638app . use ( bodyParser . json ( ) ) ;
3739app . use ( bodyParser . urlencoded ( {
@@ -49,6 +51,13 @@ app.use(express.static(path.join(__dirname, 'static'), {
4951 maxage : '7d'
5052} ) ) ;
5153
54+ //在线人数中间件
55+ app . use ( function ( req , res , next ) {
56+ var ip = getClientIp ( req ) ;
57+ redis . onlineAdd ( ip ) ;
58+ next ( ) ;
59+ } ) ;
60+
5261app . get ( '/' , function ( req , res ) {
5362 ret = '<h2>欢迎使用超星慕课刷课插件</h2><p>这个服务器将会记录你正确的答题答案,并不会记录你的任何账号信息</p>' ;
5463 ret += '<p>并且接口没有任何权限,全由插件提交上传,还请大家不要故意上传错误的答案 (๑• . •๑) </p><br/>' ;
@@ -143,11 +152,14 @@ function mergeAnswer(source, answer) {
143152}
144153
145154app . get ( '/update' , function ( req , res ) {
146- res . send ( {
147- version : config . version ,
148- url : config . update ,
149- enforce : config . enforce ,
150- injection : config . injection
155+ redis . onlineNum ( function ( err , data ) {
156+ res . send ( {
157+ version : config . version ,
158+ url : config . update ,
159+ enforce : config . enforce ,
160+ injection : config . injection ,
161+ onlinenum : data
162+ } ) ;
151163 } ) ;
152164} )
153165
0 commit comments