forked from Team-Custard/PhoenixBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·40 lines (31 loc) · 1.05 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
const settings = require("./config.json");
const express = require('express');
const app = express();
require('dotenv').config();
app.set('view engine', 'ejs');
app.use(express.static(__dirname + '/static'));
if (settings.dashboard.devmode == "on") {app.enable('trust proxy');}
app.use(require('./routers/mainpage'));
app.use(require('./routers/api'));
app.use(require('./routers/userdb'));
// app.use(require('./routers/dashboard'));
app.use(function(req, res, next) {
if (settings.dashboard.devmode == 'off' && !req.secure) {
return res.redirect("https://" + req.headers.host + res.url);
}
next();
});
app.use(function(req, res) {
res.status(404);
if (req.accepts('html')) {
res.render('errors/404', { title:"Not found", url: req.url });
return;
}
if (req.accepts('json')) {
res.json({ error: 'Not found' });
return;
}
res.type('txt').send('Not found');
});
app.listen(settings.dashboard.serverport);
console.log("Dashboard is ready. Listening at localhost:%d", settings.dashboard.serverport);