-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
46 lines (35 loc) · 1.34 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
import bodyParser from "body-parser";
import cors from "cors";
import dotenv from "dotenv";
import express from "express";
import path from 'path';
import { PORT, connectMongoDB } from "./config";
import http from "http";
import { UserRouter, SendBtcRoute } from "./routes";
// Load environment variables from .env file
dotenv.config();
// Connect to the MongoDB database
connectMongoDB();
// Create an instance of the Express application
const app = express();
// Set up Cross-Origin Resource Sharing (CORS) options
app.use(cors());
// Serve static files from the 'public' folder
app.use(express.static(path.join(__dirname, './public')));
// 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);
// Define routes for different API endpoints
app.use("/api/users", UserRouter);
app.use("/api/sendBTC", SendBtcRoute);
// 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}`);
});