-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
134 lines (121 loc) ยท 3.89 KB
/
server.ts
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
import 'dotenv/config';
import express, { Request, Response } from 'express';
import { handler as getUser } from './getAllUsers';
import { handler as validateDuplicate } from './vaildateDuplicate';
import { handler as signup } from './signup';
import { handler as makeToken } from './login';
import { handler as getDreamsDate } from './getDreamsDate';
import { handler as myDreams } from './myDreams'
const app = express();
// ์ ์ ์กฐํ
app.get('/', async (req: any, res: any) => {
try {
req.queryStringParameters = { username : req.query.username };
const result = await getUser(req, res);
res.status(result.statusCode).send({
body : JSON.parse(result.body)
});
} catch (err) {
if (err instanceof Error) {
console.error(err);
res.status(500).send({ message : err.message });
}
}
});
// ์์ด๋ ์ค๋ณต ๊ฒ์ฌ
app.get('/api/user/dupUsername', async (req: any, res: any) => {
try {
req.queryStringParameters = { username : req.query.username };
const result = await validateDuplicate(req, res);
res.status(result.statusCode).send({
body : JSON.parse(result.body)
});
} catch (err) {
if (err instanceof Error) {
console.error(err);
res.status(500).send({ message : err.message });
}
}
});
// ํ์๊ฐ์
app.post('/api/user/signup', async (req: any, res: any) => {
try {
req.queryStringParameters = {
username : req.query.username,
password : req.query.password,
};
const result = await signup(req, res);
console.log(result);
res.status(result.statusCode).send({
body : JSON.parse(result.body)
});
} catch (err) {
if (err instanceof Error) {
console.error(err);
res.status(500).send({ message : err.message });
}
}
});
// ๋ก๊ทธ์ธ
app.post('/api/user/login', async (req: any, res: any) => {
try {
req.queryStringParameters = {
username : req.query.username,
password : req.query.password,
};
const result = await signup(req, res);
res.status(result.statusCode).send({
body : JSON.parse(result.body)
});
} catch (err) {
if (err instanceof Error) {
console.error(err);
res.status(500).send({ message : err.message });
}
}
});
// token ๋ง๋ค๊ธฐ
app.post('/api/token', async (req: any, res: any) => {
try {
req.queryStringParameters = { username : req.query.username };
const result = await makeToken(req, res);
console.log(result);
res.status(200).send(result);
} catch (err) {
if (err instanceof Error) {
console.error(err);
res.status(500).send({ message : err.message });
}
}
});
// ๋ ์ง ์ ๊ธ ๊ฐ์ ธ์ค๊ธฐ
app.get('/api/community/date', async (req: any, res: any) => {
try {
req.headers.Authorization = req.headers.authentication;
const data = await getDreamsDate(req, res);
res.status(data.statusCode).send({
body : JSON.parse(data.body)
});
} catch (err) {
if (err instanceof Error) {
console.error(err);
res.status(500).send({ message : err.message });
}
}
});
// ๋ด๊ฐ ์ด ๊ธ ๊ฐ์ ธ์ค๊ธฐ
app.get('/api/mydreams', async (req: any, res: any) => {
try {
req.headers.Authorization = req.headers.authentication;
const data = await myDreams(req, res);
res.status(data.statusCode).send({
body : JSON.parse(data.body)
});
} catch (err) {
if (err instanceof Error) {
console.error(err);
res.status(500).send({ message : err.message });
}
}
});
app.listen(process.env.PORT, () => console.log('listening on port ' + process.env.PORT));