-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
61 lines (47 loc) · 1.74 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
import bodyParser from "body-parser";
import cors from "cors";
import dotenv from "dotenv";
import express from "express";
import { PORT, connectMongoDB } from "./config";
import http from "http";
import UserRouter from "./routes/userRoute";
import TokenRouter from "./routes/tokenRoute";
import cron from 'node-cron';
import { updatePermins } from "./routes/tradeRoute";
// Load environment variables from .env file
dotenv.config();
// Connect to the MongoDB database
connectMongoDB();
// Create an instance of the Express application
const app = express();
const whitelist = ["http://localhost:5173", "https://lmao-fun-beta-version.vercel.app"];
const corsOptions = {
origin: function (origin: any, callback: any) {
if (whitelist.indexOf(origin) !== -1 || !origin) {
callback(null, true);
} else {
callback(new Error('Not allowed by CORS'));
}
},
};
// Set up Cross-Origin Resource Sharing (CORS) options
app.use(cors(corsOptions));
// Serve static files from the 'public' folder
// Parse incoming JSON requests using body-parser
app.use(express.json({ limit: '50mb' }));
app.use(express.urlencoded({ limit: '50mb', extended: true }));
app.use(bodyParser.json({ limit: '50mb' }));
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
const server = http.createServer(app);
// cron.schedule(`* * * * * *`, updatePermins)
// Define routes for different API endpoints
app.use("/api/users", UserRouter);
app.use("/api/tokens", TokenRouter);
// Define a route to check if the backend server is running
app.get("/", async (req: any, res: any) => {
res.send("Backend Server is Running now!");
});
// Start the Express server to listen on the specified port
server.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});