-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
62 lines (51 loc) · 1.69 KB
/
app.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 cookieParser = require('cookie-parser');
var logger = require('morgan');
const session = require('express-session');
const SQLiteStore = require('connect-sqlite3')(session);
const sqlite3 = require('sqlite3').verbose();
const renderer = require('./renderer');
global.db = new sqlite3.Database('wikium.db', (err) => {
if (err) {
return console.error(err.message);
}
console.log('Connected to the database.');
});
// loads module and registers app specific cleanup callback...
require('./cleanup').Cleanup(myCleanup);
function myCleanup() {
db.close();
console.log('App specific cleanup code...');
}
var indexRouter = require('./routes/index');
var loginRouter = require('./routes/login');
var logoutRouter = require('./routes/logout');
var usersRouter = require('./routes/users');
var gamesRouter = require('./routes/games');
var apiRouter = require('./routes/api');
var app = express();
app.engine('tpl', renderer.render);
app.set('views', './views');
app.set('view engine', 'tpl');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static('./public'));
app.use(session({
store: new SQLiteStore,
resave: true,
saveUninitialized: true,
secret: 'keyboard cat',
cookie: { maxAge: 86400000 }
}));
app.use('/', indexRouter);
app.use('/login', loginRouter);
app.use('/logout', logoutRouter);
app.use('/games', gamesRouter);
app.use('/api', apiRouter);
app.use('/users', usersRouter);
Array.prototype.groupBy = function(key) {
return this.reduce((h, a) => Object.assign(h, { [a[key]]:( h[a[key]] || [] ).concat(a) }), {});
};
module.exports = app;