-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·57 lines (53 loc) · 1.98 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const config = require('./config.js');
const router = require('./router.js');
// const tg = require('./telegram.js');
const http = require('http');
const https = require('https');
const fs = require('fs');
const options = {
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
};
if(config.mode == "single")
{
//http
const server = http.createServer(router.OnRequest);
server.listen(config.port, config.hostname, () => {
console.log(`Server running at http://${config.hostname}:${config.port}/`);
});
//https
const httpsserver = https.createServer(options,router.OnRequest);
httpsserver.listen(config.httpsport, config.hostname, () => {
console.log(`Server running at https://${config.hostname}:${config.httpsport}/`);
});
}
else if(config.mode =="multi")
{
var cluster = require('cluster');
var numCPUs = require('os').cpus().length;
if (cluster.isMaster)
{
console.log('[master] ' + "start master...");
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('listening', function (worker, address)
{
console.log('[master] ' + 'listening: worker' + worker.id + ',pid:' + worker.process.pid + ', Address:' + address.address + ":" + address.port);
});
} else if (cluster.isWorker)
{
console.log('[worker] ' + "start worker ..." + cluster.worker.id);
var num = 0;
//http
http.createServer(router.OnRequest).listen(config.port,config.hostname, () => {
console.log(`[worker] running at http://${config.hostname}:${config.port}/`);
});
//https
const httpsserver = https.createServer(options,router.OnRequest);
httpsserver.listen(config.httpsport, config.hostname, () => {
console.log(`Server running at https://${config.hostname}:${config.httpsport}/`);
});
}
}
// tg.connect_to_bot();