-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (40 loc) · 1.29 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
const express = require("express");
const bodyParser = require("body-parser");
const routes = require("./routes/routes");
const config = require("./config");
const swaggerJsDoc = require("swagger-jsdoc");
const swaggerUi = require("swagger-ui-express");
const cors=require("cors");
const auth= require("./routes/auth");
const login= require("./routes/login")
const mongoose=require("mongoose");
mongoose.connect(config.db.url,{useNewUrlParser: true,useUnifiedTopology: true})
.then(()=>console.log("connection made succesfully"))
.catch((error)=>console.log(error))
const app = express();
// Middleware
app.use(bodyParser.json());
app.use(express.urlencoded({ extended: true }));
// Swagger configuration
const swaggerOptions = {
swaggerDefinition: {
openapi:"3.0.0",
info: {
title: "Course API",
description: "API documentation for managing courses",
version: "1.0.0"
},
basePath: "/"
},
apis: ["./routes/*.js"]
};
const swaggerSpec = swaggerJsDoc(swaggerOptions);
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerSpec));
// Routes
app.use("/courses", routes);
app.use("/register",auth);
app.use("/login",login)
const port = config.port.number;
app.listen(port, () => {
console.log(`App is running on port ${port}`);
});