-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
147 lines (99 loc) · 2.6 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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
var cookieParser = require('cookie-parser')
var express = require("express");
var app = express();
const bodyParser = require("body-parser");
const bcrypt = require('bcrypt-nodejs')
const performance = require("./performance.js")
app.use(performance.wrap(function (req, res, next) {
next();
}));
//END LOGGING PERFORMANCE
const DB = require("./Database.js");
//Custom functions
const navigator = require('./Navigator.js')
const User = require("./User.js")
DB.connect();
var allowCrossDomain = function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
}
var engine = require('consolidate');
app.use("/assets", express.static(__dirname + "/assets"));
app.use("/documentation", express.static(__dirname + "/documentation"));
app.use("/css", express.static(__dirname + "/css"));
app.use(express.static(__dirname + '/views'));
app.use('/api/discord', require('./api/discord'));
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(cookieParser())
app.engine('html', engine.mustache);
app.set('view engine', 'html');
app.use(allowCrossDomain);
/*
*
------GET-----
*
*/
app.get('/', async function (req, res) {
navigator.CheckLogin(req, res, 'dashboard')
})
app.get('/dashboard', async function (req, res) {
//res.render("dashboard")
navigator.CheckLogin(req, res, 'dashboard')
})
app.get('/login', async function (req, res) {
navigator.CheckLogin(req, res, 'dashboard')
})
app.get("/getUserInfo", async function (req, res) {
User.GetUserInfo(req.query.id).then(u => {
res.status(200).send(u);
})
})
/*
*
------POST-----
*
*/
app.post('/login', async function (req, res) {
User.Login(req, res);
})
app.post('/new_user', async function (req, res) {
User.Register(req, res);
})
/*
*
------ROUTE-----
*
*/
app.route("/logout")
.all(function (req, res) {
User.Logout(req, res);
})
/* app.route('*')
.get(function (req, res) {
navigator.CheckLogin(req, res, req.url.substring(1))
})
.post(async function (req, res) {
res.send('POST hello world')
}) */
/*
app.use(function (req, res, next) {
res.status(404).render('404_error_template', { title: "Sorry, page not found" });
}); */
app.listen(3000, () => {
console.log("Server running on port 3000");
});
/* app.use((err, req, res, next) => {
switch (err.message) {
case 'NoCodeProvided':
return res.status(400).send({
status: 'ERROR',
error: err.message,
});
default:
return res.status(404).render('404_error_template', { title: "Sorry, page not found" });
}
}); */