-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
134 lines (126 loc) · 3.52 KB
/
app.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
const express = require("express");
const mongoose = require("mongoose");
const app = express();
const dotenv = require("dotenv");
dotenv.config();
const bodyparser = require("body-parser");
const multer = require("multer");
const upload = multer();
const swaggerJsdoc = require("swagger-jsdoc");
const swaggerUi = require("swagger-ui-express");
app.use(bodyparser.urlencoded());
app.use(
bodyparser.urlencoded({
// to support URL-encoded bodies
extended: true,
})
);
app.use(bodyparser.json());
app.use(express.static(__dirname));
const options = {
definition: {
info: {
title: "Podcast Express API with Swagger",
version: "0.1.0",
description:
"This is a simple CRUD API application made with Express and documented with Swagger",
contact: {
name: "Shantesh Sindgi",
url: "",
email: "sindgishantesh@email.com",
},
},
servers: [
{
url: "http://localhost:3200/",
},
],
},
apis: [
"./routes/users.js",
"./routes/dashboard.js",
"./routes/notifications.js",
"./routes/tags.js",
"./routes/subscription.js",
"./routes/category.js",
"./routes/paymentDetails.js",
"./routes/likecomment.js",
"./routes/featureArea.js",
"./routes/playlist.js",
"./routes/audiobooks.js",
"./routes/uploads3.js",
],
};
const specs = swaggerJsdoc(options);
app.use(
"/api-docs",
swaggerUi.serve,
swaggerUi.setup(specs, { explorer: true })
);
console.log(specs);
const audiobookroute = require("./routes/audiobooks");
const userroute = require("./routes/users");
const notificationroute = require("./routes/notifications");
const tagroute = require("./routes/tags");
const subscriptionroute = require("./routes/subscription");
const categoryroute = require("./routes/category");
const paymentroute = require("./routes/paymentDetails");
const likecomment = require("./routes/likecomment");
const featureArea = require("./routes/featureArea");
const playlist = require("./routes/playlist");
const dashboard = require("./routes/dashboard");
const uploads3 = require("./routes/uploads3");
const port = process.env.PORT;
const cookieSession = require("cookie-session");
const passport = require("passport");
//require('./../Nodemon.json').config();
app.use(
cookieSession({
name: "tuto-session",
keys: ["key1", "key2"],
})
);
app.use(passport.initialize());
app.use(passport.session());
app.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept,Authorization"
);
res.setHeader(
"Access-Control-Allow-Methods",
"GET, POST, PATCH, PUT, DELETE, OPTIONS"
);
next();
});
//Routes
app.use("/users", userroute);
app.use("/notifications", notificationroute);
app.use("/tags", tagroute);
app.use("/subscriptions", subscriptionroute);
app.use("/categories", categoryroute);
app.use("/payments", paymentroute);
app.use("/likecomment", likecomment);
app.use("/featureArea", featureArea);
app.use("/playlist", playlist);
app.use("/audiolist", audiobookroute);
app.use("/dashboard", dashboard);
app.use("/uploads3", uploads3);
app.use("/", (req, res) => {
res.json("WELCOME TO SERVER");
});
// console.log(process.env.S)
// console.log(process.env.MONGO_CONNECTION);
mongoose
.connect(process.env.MONGO_CONNECTION)
.then(() => {
console.log("connected");
})
.catch((err) => {
console.log(err);
});
console.log("port", process.env.PORT);
app.listen(port, () => {
console.log("running");
});