-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (42 loc) · 1.19 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
const express = require("express");
const app = express();
const mongodb = require("./models/mongodb");
const dotenv = require("dotenv");
const bodyParser = require("body-parser");
const productController = require("./controllers/productController");
const swaggerDoc = require("swagger-ui-express");
const swaggerJsdoc = require("swagger-jsdoc");
const userController = require("./controllers/userController");
const options = {
definition: {
openapi: "3.0.0",
info: {
title: "Docs",
version: "1.0.0",
},
servers: [
{
url: "http://localhost:3000",
description: "Local server",
},
],
paths: {
"/api/product": {},
},
},
apis: ["./controllers/*.js"], // files containing annotations as above
};
const specs = swaggerJsdoc(options);
dotenv.config();
app.use(express.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// get content from the db
app.use("/api/product", productController);
app.use("/user", userController);
//db connection online
mongodb();
app.listen(3000, () => {
console.log("Server is running on port 3000");
app.use("/doc", swaggerDoc.serve, swaggerDoc.setup(specs));
});