-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
35 lines (29 loc) · 1002 Bytes
/
server.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
const dotenv = require('dotenv');
const express = require('express');
const cors = require('cors');
const cookieParser = require('cookie-parser');
const connectDB = require('./server/config/dbConnect');
const signup = require('./server/routes/SignupRoute');
const login = require('./server/routes/LoginRoute');
const reviews = require('./server/routes/reviewRoute');
const protectedRoute = require('./server/routes/protectedRoute'); // Adjust path as needed
dotenv.config({ path: '.env' });
const app = express();
const PORT = process.env.PORT || 2003;
// Middleware to parse JSON bodies
app.use(express.json());
app.use(cors({
origin: 'https://localhost:3000',
credentials: true
}));
app.use(cookieParser());
// Use the signup and login routes with a prefix
app.use('/api', signup);
app.use('/api', login);
app.use('/api', reviews);
app.use(protectedRoute);
// Connect to MongoDB
connectDB();
app.listen(PORT, () => {
console.log(`Server is running at http://localhost:${PORT}`);
});