-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
65 lines (56 loc) · 1.81 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
require("dotenv").config();
const express = require("express");
const mongoose = require("mongoose");
const app = express();
const swaggerJsDoc = require("swagger-jsdoc");
const swaggerUi = require("swagger-ui-express");
const port = process.env.PORT || 5000;
const categoriesRoutes = require("./routes/categoryRoutes");
const productRoutes = require("./routes/productRoutes");
const cartRoutes = require("./routes/cartRoutes");
const orderRoutes = require("./routes/orderRoutes");
const authRoutes = require("./routes/authRoutes");
app.use(express.json());
//swagger options
const swaggerOptions = {
definition: {
openapi: "3.0.0",
info: {
title: "E-commerce API",
version: "1.0.0",
description:
"This is e-commerce api made with express and documented with swagger",
contact: {
name: "Vivek Pratap Singh",
url: "https://vivek-pratap-singh.vercel.app/",
},
},
},
apis: ["./routes/*.js"],
};
const swaggerSpec = swaggerJsDoc(swaggerOptions);
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerSpec));
//models of the database
const Category = require("./models/Category");
const Product = require("./models/Product");
const User = require("./models/User");
const Order = require("./models/Order");
const UserCart = require("./models/UserCart");
//connecting to the database
mongoose
.connect(process.env.DB_URL)
.then((res) => {
console.log("Connected to DB");
})
.catch((err) => console.log(err));
app.get("/", (req, res) => {
res.send("Not found!");
});
app.use("/api/categories", categoriesRoutes);
app.use("/api/products", productRoutes);
app.use("/api/cart", cartRoutes);
app.use("/api/order", orderRoutes);
app.use("/api/auth", authRoutes);
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});