This repository has been archived by the owner on Nov 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
125 lines (110 loc) · 3.41 KB
/
server.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
// const { ReportWebVital, ReportCrash } = require('./utilities/misc');
require('dotenv').config()
const express = require('express'),
app = express(),
mongoose = require('mongoose'),
session = require("cookie-session"),
path = require('path'),
cookieParser = require("cookie-parser"),
expressLayouts = require('express-ejs-layouts'),
passport = require('passport');
const port = process.env.PORT || 5100,
passport_init = require('./utilities/passport'),
backlinks = require('./utilities/backlinks.json'),
bloatRouter = require('./routers/bloat'),
landingRouter = require('./routers/landing'),
playRouter = require('./routers/play'),
adminRouter = require('./routers/admin'),
profileRouter = require('./routers/profile'),
leaderboardRouter = require('./routers/leaderboard'),
authRouter = require("./routers/auth");
if (process.env.NODE_ENV === 'production') {
app.enable('trust proxy');
}
else {
app.disable('trust proxy');
}
app.use((req, res, next) => {
if (req.headers.hasOwnProperty('x-forwarded-proto') && req.headers['x-forwarded-proto'].toString() !== 'https' && process.env.NODE_ENV === 'production') {
res.redirect('https://' + req.headers.host + req.url);
}
else {
next();
}
})
//ejs
app.set('view engine', 'ejs');
app.use(express.static(path.join(__dirname, 'public')))
//mongo
const db = process.env.MONGO_URI;
//passportJs
if (process.env.NODE_ENV === 'production') {
app.use(session({
secret: process.env.SECRET,
resave: true,
saveUninitialized: true,
sameSite: 'none',
overwrite: true,
secure: true,
maxAge: 1000 * 60 * 60 * 24 * 7
}));
} else {
app.use(session({
secret: process.env.SECRET,
resave: true,
saveUninitialized: true,
}));
}
app.use(cookieParser(process.env.SECRET));
app.use(expressLayouts);
app.get('*', (req, res, next) => {
passport_init(passport, req);
next();
})
//initializing passport
app.use(passport.initialize());
app.use(passport.session());
app.use(bloatRouter);
app.use('/', landingRouter);
app.use("/auth", authRouter)
app.use('/play', playRouter)
app.use('/admin', adminRouter)
app.use('/profile', profileRouter)
app.use('/leaderboard', leaderboardRouter)
app.get('/404', (req, res) => {
res.render('404', { user: req.user });
})
app.get('/:id', (req, res, next) => {
const id = req.params.id;
const link = backlinks.find(link => link.link === id);
if (link) {
if (link.backlink) {
return res.redirect(link.backlink);
}
if (link.text) {
return res.render('hiddentext', { link });
}
}
else {
res.redirect('/404');
}
});
// app.use((err, req, res, next) => {
// ReportCrash(err.stack.toString())
// ReportWebVital("App Has Crashed, Please Check The Logs, Trying To Restart On My Own!");
// next(err)
// })
mongoose.connect(db, {
useNewUrlParser: true,
useUnifiedTopology: true,
}).then(() => {
// ReportWebVital(`Connected to Mongo DB`);
console.log("Connected to Mongo DB")
app.listen(port, () => {
// ReportWebVital(`TS Prog listening at port ${port}`);
console.log(`TS encryptid listening at http://localhost:${port}`)
})
}).catch(err => {
// ReportCrash(err.stack.toString())
// ReportWebVital("App Has Crashed, Please Check The Logs, Trying To Restart On My Own!");
})