forked from Shahanshahsidd208/KSP-Profile-Analysis-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
36 lines (29 loc) · 985 Bytes
/
app.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
require("dotenv").config();
require('express-async-errors');
//Modules
const connectDB = require("./db/connect");
const express = require("express");
const cors = require('cors')
const app = express();
const mainRouter = require("./routes/user");
const authenticateUser = require('./middleware/auth'); // Import the middleware
// Import and use searchRoutes
app.use(cors({
origin: 'http://localhost:5173', // Allow only requests from this origin
credentials: true, // Allow cookies to be sent with the request
}));
app.use(express.json());
app.use('/api/v1/dashboard', authenticateUser); // Apply middleware to dashboard route
app.use("/api/v1", mainRouter);
const port = process.env.PORT || 3000;
const start = async () => {
try {
await connectDB(process.env.MONGO_URI);
app.listen(port, () => {
console.log(`Server is listening on port ${port}`);
});
} catch (error) {
console.log(error);
}
}
start();