-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
61 lines (53 loc) · 1.59 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
var fs = require('fs'),
chalk = require('chalk'),
express = require('express'),
session = require('express-session'),
fileup = require('express-fileupload'),
bodyParser = require('body-parser'),
http = require('http'),
https = require('https'),
database = require('./database.js'),
users = require('./users.js');
const
error = chalk.redBright('ERROR'),
warning = chalk.keyword('orange')('WARN'),
info = chalk.cyan('INFO'),
HTTPS = true;
var app = express();
app.set('view engine', 'pug');
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(session({
secret: 'NaHaEztKitalalodXD',
resave: false,
saveUninitialized: false
}));
app.use(fileup({
safeFileNames: true,
useTempFiles: true,
preserveExtension: 4
}));
app.use(express.static('public'));
app.post('/login', users.login);
app.get('/logout', users.logout);
app.get('/dashboard', users.dashboard);
app.post('/upload', users.upload);
app.get('/list', users.list);
app.get('/stats', users.stats);
var httpsrv = http.createServer(HTTPS ? (req, res) => {
res.writeHead(301, { "Location": "https://" + req.headers['host'] + req.url });
res.end();
} : app);
httpsrv.listen(80);
console.log(info, 'HTTP module loaded.');
if(HTTPS){
console.log(info, 'HTTP module is redirect-only.');
var cred = {
key: fs.readFileSync('./sslcert/private.key'),
cert: fs.readFileSync('./sslcert/certificate.crt')
};
var httpssrv = https.createServer(cred, app);
httpssrv.listen(443);
console.log(info, chalk.keyword('green')('HTTPS'), 'module loaded.');
}