-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
73 lines (59 loc) · 1.86 KB
/
index.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Importing necessary modules and packages
const express = require("express")
const app = express()
const database = require("./config/db")
const dotenv = require("dotenv")
const { CONFIG } = require('./constants/config')
const { auth } = require('./middleware/auth');
// Setting up port number
const PORT = process.env.PORT || 4000
// Loading environment variables from .env file
dotenv.config()
// Connecting to database
database.connect()
const cookieParser = require("cookie-parser")
const cors = require("cors") //backend should entertain frontend's request
const { cloudinaryConnect } = require("./config/cloudinary")
const fileUpload = require("express-fileupload")
// Middlewares
app.use(express.json());
app.use(cookieParser());
app.use(
cors({
origin: process.env.CLIENT,
credentials: true,
})
)
app.use(
fileUpload({
useTempFiles: true,
tempFileDir: "/tmp/",
})
)
// Connecting to cloudinary
cloudinaryConnect()
// Importing Routes
const userRoutes = require('./routes/user');
const profileRoutes = require('./routes/profile');
const DistributionStoreRoutes = require('./routes/DistributionCenter')
const storeRoutes = require('./routes/Store');
const driverRoutes = require('./routes/driver');
const deliveriesRoutes = require('./routes/deliveries')
app.get("/", (req, res) => {
return res.json({
success: true,
message: "Your server is up and running",
})
})
// Routes
app.use(CONFIG.APIS.auth, userRoutes);
app.use(CONFIG.APIS.profile, auth, profileRoutes);
app.use(CONFIG.APIS.distribution_center, auth, DistributionStoreRoutes);
app.use(CONFIG.APIS.store, auth, storeRoutes);
app.use(CONFIG.APIS.driver, auth, driverRoutes);
app.use(CONFIG.APIS.delivery, auth, deliveriesRoutes)
// Listening to the server
app.listen(PORT, () => {
console.log(`App is listening at ${PORT}`)
})
// End of code.