-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.ts
More file actions
182 lines (163 loc) · 5.45 KB
/
Copy pathserver.ts
File metadata and controls
182 lines (163 loc) · 5.45 KB
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
import express from "express";
import { Request, Response } from "express";
import { createConnection } from "typeorm";
import morgan from "morgan";
import cors from "cors";
// APIs
import { getVaultsDaily } from "./getVaultsDaily";
import { getVaultsWeekly } from "./getVaultsWeekly";
import { getVaultsMonthly } from "./getVaultsMonthly";
import { getVaultsThreeMonths } from "./getVaultsThreeMonths";
import { getVaultsYearly } from "./getVaultsYearly";
import { getLeveragedTokensDaily } from "./getLeveragedTokensDaily";
import { getLeveragedTokensWeekly } from "./getLeveragedTokensWeekly";
import { getLeveragedTokensMonthly } from "./getLeveragedTokensMonthly";
import { getLeveragedTokensThreeMonths } from "./getLeveragedTokensThreeMonths";
import { getLeveragedTokensYearly } from "./getLeveragedTokensYearly";
import { getMarketsData } from "./getMarketsData";
import { getMarketData } from "./getMarketData";
// Rise Tokens
import { getRiseTokenThreeMonths } from "./getRiseTokenThreeMonths";
// create typeorm connection
createConnection().then((connection) => {
// create and setup express app
const app = express();
app.use(express.json());
app.use(morgan("combined"));
app.use(
cors({
origin: [
"https://risedle.com",
"http://localhost:6006",
"http://localhost:3000",
/.frontend-3mt\.pages\.dev$/,
],
})
);
app.get("/", async function (req: Request, res: Response) {
return res.send({ message: "OK" });
});
app.get("/health", async function (req: Request, res: Response) {
return res.send({ message: "OK" });
});
// Get daily data of vaults
app.get(
"/v1/vaults/daily/:id",
async function (req: Request, res: Response) {
const results = await getVaultsDaily(connection, req.params.id);
return res.send(results);
}
);
// Get weekly data of vaults
app.get(
"/v1/vaults/weekly/:id",
async function (req: Request, res: Response) {
const results = await getVaultsWeekly(connection, req.params.id);
return res.send(results);
}
);
// Get monthly data of vaults
app.get(
"/v1/vaults/monthly/:id",
async function (req: Request, res: Response) {
const results = await getVaultsMonthly(connection, req.params.id);
return res.send(results);
}
);
// Get 3 months data of vaults
app.get(
"/v1/vaults/3months/:id",
async function (req: Request, res: Response) {
const results = await getVaultsThreeMonths(
connection,
req.params.id
);
return res.send(results);
}
);
// Get 12 months data of vaults
app.get(
"/v1/vaults/yearly/:id",
async function (req: Request, res: Response) {
const results = await getVaultsYearly(connection, req.params.id);
return res.send(results);
}
);
// Get daily data of leveraged tokens
app.get(
"/v1/leveragedTokens/daily/:id",
async function (req: Request, res: Response) {
const results = await getLeveragedTokensDaily(
connection,
req.params.id
);
return res.send(results);
}
);
// Get weekly data of vaults
app.get(
"/v1/leveragedTokens/weekly/:id",
async function (req: Request, res: Response) {
const results = await getLeveragedTokensWeekly(
connection,
req.params.id
);
return res.send(results);
}
);
// Get monthly data of vaults
app.get(
"/v1/leveragedTokens/monthly/:id",
async function (req: Request, res: Response) {
const results = await getLeveragedTokensMonthly(
connection,
req.params.id
);
return res.send(results);
}
);
// Get 3 months data of vaults
app.get(
"/v1/leveragedTokens/3months/:id",
async function (req: Request, res: Response) {
const results = await getLeveragedTokensThreeMonths(
connection,
req.params.id
);
return res.send(results);
}
);
// Get 12 months data of vaults
app.get(
"/v1/leveragedTokens/yearly/:id",
async function (req: Request, res: Response) {
const results = await getLeveragedTokensYearly(
connection,
req.params.id
);
return res.send(results);
}
);
app.get("/v1/markets", async function (req: Request, res: Response) {
const results = await getMarketsData(connection);
return res.send(results);
});
app.get("/v1/markets/:id", async function (req: Request, res: Response) {
const results = await getMarketData(connection, req.params.id);
return res.send(results);
});
// Get 3 months data of rise tokens
app.get(
"/v1/riseTokens/3months/:id",
async function (req: Request, res: Response) {
const results = await getRiseTokenThreeMonths(
connection,
req.params.id
);
return res.send(results);
}
);
// start express server
console.log("Starting server :3000 ...");
app.listen(3000);
});