-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
65 lines (53 loc) · 1.46 KB
/
server.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
58
59
60
61
62
63
const cluster = require("cluster");
const os = require("os");
const log = console.log;
// 监听进程中断信号
// process.on('SIGINT', function(){
// log('进程中断');
// process.exit(0);
// });
// process.on('SIGTERM', function(){
// log('进程请求中断');
// process.exit(0);
// });
// process.on('uncaughtException', function(){
// process.exit(1);
// });
if(cluster.isMaster){
cluster.on('fork', function(worker){
log('进程创建成功 #%s [pid:%s]', worker.id, worker.process.pid);
});
cluster.on('exit', function(worker){
log('进程退出 #%s [pid:%s]', worker.id, worker.process.pid);
// setTimeout(function(){
// cluster.fork();
// });
});
cluster.fork();
return;
}
const express = require("express");
const path = require("path");
const port = process.env.PORT || 8001;
const app = express();
const cors = require("cors");
const session = require("express-session");
const bodyParser = require("body-parser");
const Router = require("./admin/router/routes");
app.locals.moment = require("moment");
app.set('view engine', 'html');
app.engine('html', require('ejs').renderFile);
app.set('views', path.join(__dirname, "admin/views"));
app.use(express.static(path.join(__dirname, "public")));
app.use(bodyParser.urlencoded({extended: true})) ;
app.use(cors());
app.use(session({
// 新增
resave: true,
// 新增
saveUninitialized: true,
secret: 'MYSQL'
})) ;
Router(app);
app.listen(port);
log('服务启动: http://localhost:' + port);