-
Notifications
You must be signed in to change notification settings - Fork 1
/
httpTest.js
74 lines (70 loc) · 1.65 KB
/
httpTest.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
import http from "node:http";
import readline from "node:readline";
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.question("login? or signup?: ", (method) => {
if (method==="login") login()
else if(method==="signup") signup()
});
function login() {
rl.question("{email} {password} plz: ", (input) => {
let [email, password] = input.split(" ");
const body = JSON.stringify({ email, password });
const req = http.request(
{
port: 3000,
host: "localhost",
path: "/account/login",
method: "POST",
headers: {
"Content-Type": "application/json",
},
},
(res) => {
res.setEncoding("utf-8");
res.on("data", (data) => {
console.log(data);
//console.log(JSON.parse(data));
});
}
);
console.log(body);
req.write(body);
req.end();
});
}
function signup() {
rl.question("{email} {password} {nickname} plz: ", (input) => {
let [email, password, nickname] = input.split(" ");
let allowNotice = true;
const body = JSON.stringify({
email,
password,
nickname,
allowNotice,
});
const req = http.request(
{
port: 3000,
host: "localhost",
path: "/account/signup",
method: "POST",
headers: {
"Content-Type": "application/json",
},
},
(res) => {
res.setEncoding("utf-8");
res.on("data", (data) => {
console.log(data);
//console.log(JSON.parse(data));
});
}
);
console.log(body);
req.write(body);
req.end();
});
}