-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
84 lines (65 loc) · 2.79 KB
/
index.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
import bodyParser from "body-parser";
import cors from "cors";
import dotenv from "dotenv";
import express from "express";
import http from "http";
// Configuration Settings from config file, .env file
import { PORT } from "./config/config";
// Mutex for API Rate limit protection functionality
import { Mutex } from "async-mutex";
// Swagger UI implementation
import swaggerUi from "swagger-ui-express";
import YAML from "yamljs";
// API endpoint Routers
import DifferentAmountRouter from "./routes/AirdropRoute/different-amount.route";
import RedeemRunestoneFeeRouter from "./routes/SubRoute/runestone-fee.route";
import SameAmountRouter from "./routes/AirdropRoute/same-amount.route";
import EstimateDifferentAmountRouter from "./routes/EstimateRoute/different-amount-estimate.route";
import EstimateSameAmountRouter from "./routes/EstimateRoute/same-amount-estimate.route";
import LargeDifferentAmountRouter from "./routes/AirdropRoute/large-different-amount.route";
import DifferentAmountAirdropRouter from "./routes/AirdropRoute/large-different-amount-airdrop.route";
// Mutex Variable setting for API Rate Limit functionality
export const flagMutex = new Mutex();
export const iterator = new Mutex();
// Load environment variables from .env file
dotenv.config();
// Initialize Swgger UI
let swaggerDocument: any = YAML.load("swagger.yaml");
// Create an instance of the Express application
const app = express();
// Set up Cross-Origin Resource Sharing (CORS) options
app.use(cors());
// Parse incoming JSON requests using body-parser
app.use(bodyParser.json({ limit: "50mb" }));
app.use(express.json({ limit: "50mb" }));
app.use(bodyParser.urlencoded({ limit: "50mb", extended: true }));
app.use(express.urlencoded({ limit: "50mb", extended: true }));
const server = http.createServer(app);
// Define a route to check if the backend server is running
app.get("/", async (req: any, res: any) => {
res.send("Rune Airdrop Backend is Running now!");
});
// Define routes for different API endpoints
app.use("/api", RedeemRunestoneFeeRouter);
app.use("/api", SameAmountRouter);
app.use("/api", DifferentAmountRouter);
app.use("/api", LargeDifferentAmountRouter)
app.use("/api", DifferentAmountAirdropRouter)
// Define routes for estimate airdrop transaction fee
app.use("/api/estimate", EstimateSameAmountRouter);
app.use("/api/estimate", EstimateDifferentAmountRouter);
// Swagger endpoint Settings
app.use(
"/api-docs",
swaggerUi.serve,
swaggerUi.setup(swaggerDocument, { explorer: true })
);
// Set Global Variable Iterator for Wallet management
app.locals.walletIndex = 0;
// Set Global Variable Iterator for unisat api distribution
app.locals.iterator = 0;
// Start the Express server to listen on the specified port
server.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
export default app;