-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
103 lines (99 loc) · 3.76 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
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
const http = require('http');
const ejs = require('ejs');
const {GetSCV,SetSCV,FilterGoods, FilterUserGoods} = require('./csv');
const server = http.createServer(async (req, res) => {
const url = req.url;
console.log(url)
if (url === '/') {
if(req.method === 'POST'){
let body = '';
req.on('data', chunk => {
body += chunk.toString();
});
req.on('end', () => {
// 处理接收到的数据
const urlParams = new URLSearchParams(body);
const obj = Object.fromEntries(urlParams.entries());
let sex =[]
obj.sex1=='1'?sex.push(1):''
obj.sex2=='2'?sex.push(2):''
obj.sex3=='3'?sex.push(3):''
console.log(obj,sex);
SetSCV({email:obj.email,sex})
// 发送响应
ejs.renderFile('ejs/200.ejs', {}, (err, html) => {
res.writeHead(200, {'Content-Type': 'text/html;charset=utf-8'});
res.end(html);
})
});
}else {
ejs.renderFile('ejs/index.ejs', {}, (err, html) => {
if (err) {
console.error(err);
res.statusCode = 500;
res.end('Server Error');
} else {
res.writeHead(200, {'Content-Type': 'text/html;charset=utf-8'});
res.end(html);
}
})
}
} else if (url === '/uMail?sex=1') {
let data = FilterGoods(await GetSCV('csv/uMailM.csv'))
await ejs.renderFile('ejs/mail.ejs', {
title: "8月8日-8月15日 男装", data }, (err, html) => {
if (err) {
console.error(err);
res.statusCode = 500;
res.end('Server Error');
} else {
res.writeHead(200, {'Content-Type': 'text/html;charset=utf-8'});
res.end(html);
}
})
} else if (url === '/uMail?sex=2') {
let data = FilterGoods(await GetSCV('csv/uMailW.csv'))
await ejs.renderFile('ejs/mail.ejs', {
title: "8月8日-8月15日 女装", data }, (err, html) => {
if (err) {
console.error(err);
res.statusCode = 500;
res.end('Server Error');
} else {
res.writeHead(200, {'Content-Type': 'text/html;charset=utf-8'});
res.end(html);
}
})
}else if (url === '/uMail?sex=3') {
let data = FilterGoods(await GetSCV('csv/uMailK.csv'))
await ejs.renderFile('ejs/mail.ejs', {title: "8月8日-8月15日 童装", data }, (err, html) => {
if (err) {
console.error(err);
res.statusCode = 500;
res.end('Server Error');
} else {
res.writeHead(200, {'Content-Type': 'text/html;charset=utf-8'});
res.end(html);
}
})
} else if(url=== '/mail'){
let data = await FilterUserGoods(['1','2','3'])
let html = await ejs.renderFile('ejs/mail.ejs', {title: '8月8日-8月15日 限时折扣', data })
res.writeHead(200, {'Content-Type': 'text/html;charset=utf-8'});
res.end(html);
} else {
ejs.renderFile('ejs/404.ejs', {}, (err, html) => {
if (err) {
console.error(err);
res.statusCode = 500;
res.end('Server Error');
} else {
res.writeHead(200, {'Content-Type': 'text/html;charset=utf-8'});
res.end(html);
}
})
}
});
server.listen(3000, () => {
console.log('Server running at http://localhost:3000/');
});