-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
90 lines (79 loc) · 2.13 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
// index.js
import express from "express";
import cors from "cors";
import apiIndex from "./api/index.js";
import tokenApi from "./api/tokens.js";
import nftApi from "./api/nfts.js";
import historyApi from "./api/history.js";
import defiApi from "./api/defi.js";
import pnlApi from "./api/pnl.js";
import approvalsApi from "./api/approvals.js";
import spamApi from "./api/spamCheck.js";
import path from "path";
const __dirname = path.resolve();
import { rateLimit } from "express-rate-limit";
const limiter = rateLimit({
windowMs: 1 * 60 * 1000,
limit: 100,
standardHeaders: "draft-7",
legacyHeaders: false,
});
const app = express();
app.use(express.json());
app.use(cors());
import http from "http";
const server = http.createServer(app);
app.use(express.static(path.resolve(__dirname, "./client/build")));
app.use(validateChain);
app.use(limiter);
app.use("/", apiIndex);
app.use("/", tokenApi);
app.use("/", nftApi);
app.use("/", historyApi);
app.use("/", defiApi);
app.use("/", pnlApi);
app.use("/", approvalsApi);
app.use("/", spamApi);
const chains = [
"eth",
"polygon",
"bsc",
"base",
"gnosis",
"optimism",
"fantom",
"avalanche",
"arbitrum",
"cronos",
"palm",
];
function validateChain(req, res, next) {
const requestedChain = req.query.chain;
// Check if req.query.chain exists
if (requestedChain) {
// Check if the requested chain is in the supported list
if (chains.includes(requestedChain)) {
// If supported, set req.chain to req.query.chain
req.chain = requestedChain;
} else {
// If not supported, default to req.chain = "eth"
req.chain = "eth";
}
} else {
// If req.query.chain does not exist, default to req.chain = "eth"
req.chain = "eth";
}
// Continue to the next middleware or route handler
next();
}
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "./client/build", "index.html"));
});
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send("Something broke!");
});
const PORT = process.env.PORT || 3001;
server.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});