-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
38 lines (31 loc) · 1.07 KB
/
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
36
37
38
const express = require('express')
const connectDB = require('./config/db');
require('dotenv').config();
const cors = require('cors');
const path = require('path');
//Middleware
const { errorResponseHandler, invalidPathHandler } = require('./middleware/errorHandler');
//Routes
const userRoutes = require('./routes/userRoutes');
const postRoutes = require('./routes/postRoutes');
const commentRoutes = require('./routes/commentRoutes');
connectDB();
const PORT = process.env.PORT;
const app = express();
app.use(cors());
// app.use(cors({
// origin: ['https://blog-website-server-seven.vercel.app/'],
// methods: ["POST", "PUT", "DELETE", "GET"],
// credentials: true
// }));
app.use(express.json());
app.get('/',(req,res)=>{
res.send('Server is running')
});
app.use('/api/users',userRoutes);
app.use('/api/posts',postRoutes);
app.use('/api/comments',commentRoutes);
app.use('/uploads', express.static(path.join(__dirname, '/uploads')));
app.use(invalidPathHandler);
app.use(errorResponseHandler);
app.listen(PORT,()=>console.log('Server is live on port # ' + PORT))