-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
134 lines (122 loc) · 3.87 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
let express = require("express");
let mongoose = require("mongoose");
const dotenv = require("dotenv");
const path = require("path");
const cors = require("cors");
const http = require("http");
const https = require("https");
const morgan = require('morgan')
var admin = require("firebase-admin");
const cookieParser = require("cookie-parser");
const bodyParser = require("body-parser");
const methodOverride = require("method-override");
var fs = require("fs");
const Razorpay = require("razorpay");
dotenv.config();
let app = express();
const httpapp = express();
var serviceAccount = require("./fb/serviceAccountKey.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
});
mongoose.connect(
process.env.DATABASE,
{
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true,
},
() => console.log("Connected to db")
);
const paytmRoutes = require("./routes/paytm");
let Quiz = require("./models/quiz");
const razorPayRoute = require("./routes/payment");
const authRoute = require("./routes/auth");
const dashboardRoute = require("./routes/dashboard");
const questionRoute = require("./routes/questionRouter");
const quizRoute = require("./routes/quizRouter");
const userRoute = require("./routes/user");
const responseRoute = require("./routes/response");
const subscriptionRoute = require("./routes/subscription");
const fileRoute = require("./routes/fileUpload");
const leaderboardRoute = require("./routes/leaderboard");
const feedRoute = require("./routes/feedRouter");
const fcmRoute = require("./routes/notification");
const offerRoute = require("./routes/offerRouter");
// const paymentRoute = require("./routes/payment");
const instance = new Razorpay({
key_id: process.env.KEY_ID,
key_secret: process.env.KEY_SECRET,
});
//Middlewares
app.use(cors());
app.use(express.json());
app.use(morgan('combined'))
app.use(cookieParser());
app.use(
bodyParser.urlencoded({
extended: false,
})
);
httpapp.get("*", function (req, res, next) {
res.redirect("https://" + req.headers.host + req.path);
});
app.use(bodyParser.json());
app.use(methodOverride("_method"));
app.use(express.static(__dirname + "/public"));
app.set("view engine", "ejs");
app.set("views", path.join(__dirname, "views"));
app.get("/", function (req, res) {
res.render("adminUI/landing");
});
app.get("/privacy", (req, res) => {
res.render("adminUI/privacy-policy");
});
app.get("/terms", (req, res) => {
res.render("adminUI/terms-conditions");
});
app.get("/refund", (req, res) => {
res.render("adminUI/refund-policy");
});
app.get("/upload/:name", function (req, res) {
const src = fs.createReadStream(`./uploads/${req.params.name}`);
src.pipe(res);
});
app.get("/api/app/time", (req, res) => {
var date = new Date();
console.log(date);
res.json({ "date": date.getTime() });
})
app.use(authRoute);
app.use("/paytm", paytmRoutes);
app.use("/api/admin/dashboard", dashboardRoute);
app.use("/quiz", quizRoute);
app.use("/quiz/:id/questions", questionRoute);
app.use("/quiz/:id/leaderboard", leaderboardRoute);
app.use("/user", userRoute);
//POST response
app.use("/response", responseRoute);
app.use("/fcm", fcmRoute);
app.use("/subscription", subscriptionRoute);
app.use("/razorPay", razorPayRoute);
app.use("/file", fileRoute);
app.use("/feed", feedRoute);
app.use("/offer", offerRoute);
require("./cron/quizcron");
// app.listen(3000, () => console.log("Server started"));
const httpServer = http.createServer(httpapp);
httpServer.listen(80, () => {
console.log("HTTP Server running on port 80");
});
const httpsServer = https.createServer(
{
key: fs.readFileSync(path.resolve(__dirname, "./ssl/key.pem")),
cert: fs.readFileSync(path.resolve(__dirname, "./ssl/cert.pem")),
ca: fs.readFileSync(path.resolve(__dirname, "./ssl/fullchain.pem")),
},
app
);
httpsServer.listen(443, () => {
console.log("HTTPS Server running on port 443");
});