-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue.config.js
251 lines (247 loc) · 6.77 KB
/
vue.config.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
246
247
248
249
250
251
module.exports = {
css: {
loaderOptions: {
stylus: {
"resolve url": true,
import: ["./src/theme"]
}
}
},
pluginOptions: {
"cube-ui": {
postCompile: true,
theme: true
}
},
configureWebpack: {
devServer: {
before(app) {
// 中间件
// app.use(function(req, res, next) {
// // 检查token
// if (/^\/api/.test(req.path)) {
// // 之校验/api开头的请求
// console.log(req.method + " " + req.path);
// console.log("token:" + req.headers.token);
// // console.log(req)
// if (req.path == "/api/login" || req.headers.token) {
// next();
// } else {
// res.sendStatus(401); // 错误状态提示用户需要登录
// }
// } else {
// next();
// }
// });
app.get("/api/goods", function(req, res) {
res.json({
code: 0,
slider: [
{
id: 21,
img: "/img/01.jpg"
},
{
id: 22,
img: "/img/02.jpg"
},
{
id: 23,
img: "/img/03.jpg"
},
{
id: 24,
img: "/img/04.jpg"
}
],
data: {
fe: [
{
id: 1,
title: "Vue2.x实战",
price: "100",
img: "/img/01.jpg",
count: 100
},
{
id: 2,
title: "React16.x实战",
price: "120",
img: "/img/03.jpg",
count: 100
},
{
id: 3,
title: "nodejs实战",
price: "80",
img: "/img/02.jpg",
count: 100
},
{
id: 4,
title: "前端工程化",
price: "110",
img: "/img/04.jpg",
count: 100
},
{
id: 5,
title: "面试",
price: "200",
img: "/img/02.jpg",
count: 100
},
{
id: 6,
title: "前端安全",
price: "30",
img: "/img/05.jpg",
count: 100
}
],
python: [
{
id: 7,
title: "Python基础语法",
price: "120",
img: "/img/03.jpg",
count: 101
},
{
id: 8,
title: "Flask实战",
price: "80",
img: "/img/02.jpg",
count: 100
},
{
id: 9,
title: "Django实战",
price: "110",
img: "/img/01.jpg",
count: 100
},
{
id: 10,
title: "Python语法进阶",
price: "200",
img: "/img/04.jpg",
count: 100
}
],
java: [
{
id: 11,
title: "java入门实战",
price: "80",
img: "/img/02.jpg",
count: 100
},
{
id: 12,
title: "spring boot实战",
price: "110",
img: "/img/01.jpg",
count: 100
},
{
id: 13,
title: "Java高并发",
price: "30",
img: "/img/04.jpg",
count: 100
}
],
bigdata: [
{
id: 14,
title: "大数据实战",
price: "200",
img: "/img/01.jpg",
count: 100
},
{
id: 15,
title: "Hadoop实战",
price: "120",
img: "/img/03.jpg",
count: 100
},
{
id: 16,
title: "Kafka平台",
price: "80",
img: "/img/02.jpg",
count: 100
}
],
ai: [
{
id: 17,
title: "算法实战",
price: "100",
img: "/img/01.jpg",
count: 100
},
{
id: 18,
title: "个性化推荐",
price: "120",
img: "/img/03.jpg",
count: 100
},
{
id: 19,
title: "机器学习",
price: "80",
img: "/img/02.jpg",
count: 100
},
{
id: 20,
title: "AI实战",
price: "110",
img: "/img/05.jpg",
count: 100
}
]
},
keys: ["fe", "python", "java", "bigdata", "ai"]
});
});
app.post("/api/login", function(req, res) {
console.log("用户登录");
// console.log(req);
let body = [];
req
.on("data", chunk => {
// 接收到一部分数据
console.log(chunk); //chunk是Buffer对象
body.push(chunk);
})
.on("end", () => {
// 数据接收完毕
// 将body转换为完整的buffer
body = Buffer.concat(body).toString();
// 转换并保存前台传递的user
const { username, password } = JSON.parse(body); //{name:'aaa',age:20}
if (username === "jerry" && password === "123") {
res.json({
code: 0,
token: "jilei"
});
} else {
res.json({
code: -1,
message: "用户名或密码错误"
});
}
});
});
app.get("/api/logout", function(req, res) {
res.json({ code: -1 });
});
}
}
}
};