代码拉取完成,页面将自动刷新
/*
* +-------------------------------------------+
* | MIITVIP |
* +-------------------------------------------+
* | Copyright (c) 2020 makeit.vip |
* +-------------------------------------------+
* | Author: makeit <lirongtong@hotmail.com> |
* | Homepage: https://www.makeit.vip |
* | Github: https://git.makeit.vip |
* | Date: 2020-9-10 9:44 |
* +-------------------------------------------+
*/
const Koa = require('koa');
const cors = require('@koa/cors');
const redis = require('redis');
/** app */
const app = new Koa();
app.use(cors);
/** format current time */
function getTime() {
const date = new Date(),
year = date.getFullYear().toString(),
month = date.getMonth(),
day = date.getDate(),
hour = date.getHours(),
mins = date.getMinutes(),
secs = date.getSeconds(),
mon = month + 1;
return `${year}-${mon < 10 ? '0' + mon : mon}-${day < 10 ? '0' + day : day} ${hour < 10 ? '0' + hour : hour}:${mins < 10 ? '0' + mins : mins}:${secs < 10 ? '0' + secs : secs}`;
}
/** redis */
const pub = redis.createClient(6379, '127.0.0.1');
pub.on('error', (err) => {
console.log(`redis server error: ${err} ( ${getTime()} )`);
}).on('connect', () => {
console.log(`redis server is up and running ... ( ${getTime()} )`);
});
/** socket instance */
const prefix = 'mi-',
server = require('http').createServer(app.callback()),
io = require('socket.io')(server);
io.set('origins', '*:*');
console.log(`socket server is up and running... ( ${getTime()} )`);
/** events */
io.on('connection', (socket) => {
console.log(`handshake:${socket.handshake.address} ( ${getTime()} )`);
/** listeners */
socket.on('init', () => {
}).on('disconnect', () => {
console.log(`waved:${socket.handshake.address} ( ${getTime()} )`);
})
});
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。