-
Notifications
You must be signed in to change notification settings - Fork 15
/
app.js
62 lines (51 loc) · 1.68 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
/**
* Module dependencies.
*/
const express = require('express')
, http = require('http')
, path = require('path')
, Umzug = require('umzug')
, bodyParser = require('body-parser')
, cron = require('node-cron')
, Datastore = require('@seald-io/nedb')
, routes = require('./routes')
, i18n = require("i18n");
;
const app = express();
const umzug = new Umzug();
// default: using 'accept-language' header to guess language settings
app.use(i18n.init);
app.set('port', process.env.PORT || 3300);
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.Router());
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.urlencoded({ extended: false }));
app.enable('trust proxy');
app.disable( 'x-powered-by' )
const nedb = new Datastore({filename: 'data/read2burn.db', autoload: true});
exports.nedb = nedb
i18n.configure({
locales: ['en', 'de'],
directory: __dirname + '/locales',
defaultLocale: 'en'
});
app.get('/', routes.index);
app.post('/', routes.index);
umzug.up().then(function (migrations) {
// "migrations" will be an Array with the names of the
// executed migrations.
});
// start server
http.createServer(app).listen(app.get('port'), function () {
console.log("Express server listening on port " + app.get('port'));
});
// schedule regular cleanup
cron.schedule('12 1 * * *', function () {
console.log("Cleanup proceeding...")
const expireTime = new Date().getTime() - 8640000000;
nedb.remove({timestamp: {$lte: expireTime}}, { multi: true }, function(err, numDeleted) {
console.log('Deleted', numDeleted, 'entries');
nedb.persistence.compactDatafile();
});
});