-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
65 lines (52 loc) · 1.78 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
// Importing Packages and Libraries
const express = require("express");
const cors = require('cors');
const config = require('./Config/URL/config');
// Extracting files and configurations
require("dotenv").config();
const connectDB = require("./Config/DB/connection");
connectDB();
// Import Routes
const homeRouter = require("./src/Routes/Home/home.route");
const userRouter = require("./src/Routes/User/user.route");
const authRouter = require("./src/Routes/Authentication/auth.route");
const productRouter = require("./src/Routes/Product/product.route");
const paymentRouter = require("./src/Routes/Payment/payment.route");
const orderRouter = require("./src/Routes/Orders/orders.route");
// setting configurations
const app = express();
const PORT = process.env.PORT || 8080;
// middlewares
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
// Create a new router for /api/v1 & Use Routes as middlewares
const apiRouter = express.Router();
apiRouter.use('/home', homeRouter);
apiRouter.use('/user', userRouter);
apiRouter.use('/auth', authRouter);
apiRouter.use('/product', productRouter);
apiRouter.use('/payment', paymentRouter);
apiRouter.use('/orders', orderRouter);
// Use the apiRouter
app.use('/api/v1', apiRouter);
// Default route
app.get('/', (req, res) => {
try {
res.status(200).json({
success: true,
message: "Welcome to Dhiwise",
server: `Backend URL is: ${config.backendUrl}`
});
} catch (error) {
console.error("ERROR IN Home ROUTE:", error);
res.status(500).json({
success: false,
});
}
});
// Server listening
app.listen(PORT, () => {
console.log(`App running on port ${PORT}`);
console.log(`Server is running on ${config.backendUrl}`);
})