-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·62 lines (48 loc) · 1.72 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
var express = require('express');
var exphbs = require('express-handlebars');
var bodyParser = require('body-parser');
var auth = require('./app/auth');
var routers = require('./routers');
var csurf = require('csurf')({ cookie: true });
var helmet = require('helmet');
var expressLocale = require('express-locale');
var app = express();
app.use(bodyParser.json());
var hbs = exphbs.create({
helpers: require('handlebars-helpers')()
});
app.engine('handlebars', hbs.engine);
app.set('view engine', 'handlebars');
// Setup databases first
let database = require('./app/database');
function initRest () {
auth.initialize(app);
app.use(helmet.contentSecurityPolicy({
directives: {
defaultSrc: ["'self' blob:"],
imgSrc: ['* data:'],
mediaSrc: ['*'],
scriptSrc: ["'self' 'unsafe-inline' www.speedrun.com blob:"],
styleSrc: ["'self' 'unsafe-inline' https://fonts.googleapis.com/ https://fonts.gstatic.com/"],
fontSrc: ["'self' data: https://fonts.gstatic.com"]
}
}));
app.use(csurf);
app.use(expressLocale());
app.use(express.static('public'));
routers.setupRouting(app, express.Router());
if (!database.admin.isSetupDone() && !database.admin.getConnection('twitch').isSetup) {
var password = Math.random().toString(36).substring(2);
database.admin.setSetupPassword(password);
console.log('The setup password is: \'' + password + '\'');
}
}
const port = 8092;
app.listen(port, function () {
console.log(`Started listening on port :${port}`);
console.log('Starting rest initialization after 1 second...');
setTimeout(initRest, 1000);
});
process.on('unhandledRejection', (reason, full) => {
console.log(full);
});