-
Notifications
You must be signed in to change notification settings - Fork 0
/
node-index.js
245 lines (219 loc) · 6.06 KB
/
node-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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
const chartData = require("./util/getObjectData");
const http = require("http");
const { routers } = require("./routers");
const {
getList,
getSimpleBlog,
deleteSimple,
updateSimpleBlog,
createBlog,
login,
register,
getUserInfo,
upload,
editorUserInfo,
getLoginCount,
getWordCloud,
getActiveAuthor,
getMaxBlog,
getOneDayForScatter,
authorAddress,
getLogs,
setLogs,
} = require("./util/dealRequest");
const { SuccessModal, ErrorModal } = require("./src/modal");
http.createServer(routers).listen(8000);
// 注册路由
routers.get("/api/getList", (req, res) => {
getList(req, res).then((result) => {
return res.end(JSON.stringify(new SuccessModal(result, "请求成功")));
});
});
// 获取单个详情的接口
routers.get("/api/getSimpleBlog", (req, res) => {
getSimpleBlog(req, res).then(
(result) => {
return res.end(JSON.stringify(new SuccessModal(result, "请求成功")));
},
(error) => {
return res.end(JSON.stringify(new ErrorModal("", error)));
}
);
});
// 这个是删除的接口
routers.get("/api/deleteSimple", (req, res) => {
deleteSimple(req, res).then(
(result) => {
return res.end(JSON.stringify(new SuccessModal("", result)));
},
(error) => {
return res.end(JSON.stringify(new ErrorModal("", error)));
}
);
});
// 这个是更新的接chengg
routers.post("/api/updateSimpleBlog", (req, res) => {
updateSimpleBlog(req, res).then((result) => {
return res.end(JSON.stringify(new SuccessModal("", result)));
});
});
// 这个是新建的接口
routers.post("/api/createBlog", (req, res) => {
createBlog(req, res).then((result) => {
return res.end(JSON.stringify(new SuccessModal(result, "请求成功")));
});
});
// 登陆接口
// routers.post("/api/login", (req, res) => {
// const fork = require('child_process').fork; // 创建进程函数
// const child = fork('./process/calaculate.js'); // 创建一个进程
// // 父进程监听
// child.on('message', (data) => {
// // 获取子进程的id
// console.log(data, 'child pid...');
// })
// // 父进程发送消息
// child.send('test');
// login(req, res).then(
// (result) => {
// return res.end(JSON.stringify(new SuccessModal(result, "登录成功")));
// },
// (error) => {
// return res.end(JSON.stringify(new ErrorModal("", error)));
// }
// );
// });
// 注册接口
// routers.post("/api/register", (req, res) => {
// return register(req, res).then(
// (result) => {
// return res.end(JSON.stringify(new SuccessModal(result, "注册成功")));
// },
// (error) => {
// return res.end(JSON.stringify(new ErrorModal("", error)));
// }
// );
// });
// 获取个人信息接口
routers.get("/api/getUserInfo", (req, res) => {
getUserInfo(req, res).then(
(result) => {
return res.end(JSON.stringify(new SuccessModal(result)));
},
(error) => {
return res.end(JSON.stringify(new ErrorModal("", error)));
}
);
});
// 修改个人接口1
routers.post("/api/editorUserInfo", (req, res) => {
editorUserInfo(req, res).then(
(result) => {
return res.end(JSON.stringify(new SuccessModal(result)));
},
(error) => {
return res.end(JSON.stringify(new ErrorModal("", error)));
}
);
});
// 上传接口
// routers.post("/api/upload", (req, res) => {
// upload(req, res).then(
// (result) => {
// return res.end(JSON.stringify(new SuccessModal(result)));
// },
// (error) => {
// return res.end(JSON.stringify(new ErrorModal("", error)));
// }
// );
// });
// 获取一周登录数据
routers.get("/api/getLoginCount", (req, res) => {
getLoginCount(req, res).then(
(result) => {
return res.end(JSON.stringify(new SuccessModal(result)));
},
(error) => {
return res.end(JSON.stringify(new ErrorModal("", error)));
}
);
});
// 获取标签云接口
routers.get("/api/getWordCloud", (req, res) => {
getWordCloud(req, res).then(
(result) => {
return res.end(JSON.stringify(new SuccessModal(result)));
},
(error) => {
return res.end(JSON.stringify(new ErrorModal("", error)));
}
);
});
// 获取活跃用户
routers.get("/api/getActiveAuthor", (req, res) => {
getActiveAuthor(req, res).then(
(result) => {
return res.end(JSON.stringify(new SuccessModal(result)));
},
(error) => {
return res.end(JSON.stringify(new ErrorModal("", error)));
}
);
});
// 获取最大博客用户信息
routers.get("/api/getMaxBlog", (req, res) => {
getMaxBlog(req, res).then(
(result) => {
return res.end(JSON.stringify(new SuccessModal(result)));
},
(error) => {
return res.end(JSON.stringify(new ErrorModal("", error)));
}
);
});
// 获取一周内00:00-24:00 内的发布文章散点图
routers.get("/api/oneDayPublish", (req, res) => {
getOneDayForScatter(req, res).then((result) => {
// 在这里维护一张00:00-24:00的对象
// 对立resule,更改表格的数据
const data = Array.isArray(result) ? result : [];
data.forEach((item) => {
const { timeHour, number } = item || {};
chartData.timeRange[timeHour] = number;
});
return res.end(JSON.stringify(new SuccessModal(chartData.timeRange)));
});
});
// 获取作者(位置图数据
routers.get("/api/authorAddress", (req, res) => {
authorAddress(req, res).then(
(result) => {
return res.end(JSON.stringify(new SuccessModal(result)));
},
(error) => {
return res.end(JSON.stringify(new ErrorModal("", error)));
}
);
});
// 获取日志操作
routers.get("/api/log", (req, res) => {
getLogs(req, res).then(
(result) => {
return res.end(JSON.stringify(new SuccessModal(result)));
},
(error) => {
return res.end(JSON.stringify(new ErrorModal("", error)));
}
);
});
//设置日志操作
routers.post("/api/setLog", (req, res) => {
setLogs(req, res).then(
(result) => {
return res.end(JSON.stringify(new SuccessModal(result)));
},
(error) => {
return res.end(JSON.stringify(new ErrorModal("", error)));
}
);
});