-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
59 lines (47 loc) · 1.44 KB
/
index.js
File metadata and controls
59 lines (47 loc) · 1.44 KB
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
import express from 'express';
import cors from 'cors';
import mongoose from 'mongoose';
import dotenv from 'dotenv';
import roleRouter from './routes/role.js';
import authRouter from './routes/auth.js';
import userRouter from './routes/user.js';
import blogRouter from './routes/blog.js';
import cookieParser from 'cookie-parser';
const app = express();
dotenv.config();
app.use(express.json());
app.use(cookieParser());
app.use(cors({
origin:'http://localhost:4200/',
credentials : true
}))
app.use("/api/role", roleRouter);
app.use('/api/auth', authRouter);
app.use('/api/user', userRouter);
//app.use('/api/blog', blogRouter);
;
//Response Handler Middleware
// app.use((obj, req, res, next) =>{
// const statusCode = obj.status || 500;
// const message = obj.message || "Something Went Wrong!";
// return res.status(statusCode).json({
// success : [200,201,204].some(a => a === obj.status) ? true : false,
// status : statusCode,
// message : message,
// data : obj.data
// });
// });
//Server Connection
app.listen(8080, () =>{
connectMongoDB();
console.log("----********Connected with Backend Server********----");
})
//Mongo DB Connection
const connectMongoDB = async () =>{
try {
await mongoose.connect(process.env.MONGO_CONNECTION_URL);
console.log("----********Connected with Mongo Database********----")
} catch (error) {
throw error;
}
}