This repository has been archived by the owner on Mar 2, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server.js
70 lines (54 loc) · 1.57 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
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config();
}
const express = require('express');
const methodOverride = require('method-override');
const mongoose = require('mongoose');
const log = require("./lib/Loggers");
const flash = require('connect-flash');
const session = require('express-session');
const cors = require("cors");
const app = express();
mongoose.connect(process.env.MONGODB_NAV, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
let db = mongoose.connection;
app.use(
session({
secret: process.env.SESSION_SECRET,
resave: true,
saveUninitialized: true,
})
);
app.use(flash());
app.use(cors({
origin: "*",
}));
app.use(function (req, res, next) {
res.locals.success_msg = req.flash('success_msg');
res.locals.error_msg = req.flash('error_msg');
res.locals.error = req.flash('error');
res.locals.video = req.flash('video');
res.setHeader('X-Powered-By', 'Tolfix');
next();
});
app.set('view engine', 'ejs');
app.use(express.static('public'));
//Override
app.use(methodOverride('_method'));
// Express body parser
app.use(express.urlencoded({ extended: true }));
//Routers goes here
app.use("/r", require("./routes/Redirect"));
app.use("/api", require("./routes/API"));
app.get("/", (req, res) => {
res.render("main");
});
const PORT = process.env.PORT || 8080;
app.listen(PORT, log.verbos(`Server started on port ${PORT}`));
app.get('*', (req, res) => {
res.status(404).render('partials/notFound');
});
require("./events/MongooseEvents")(db);
require("./events/NodeEvents")()