-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathserver.js
62 lines (47 loc) · 1.67 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
(function () {
"use strict";
var bunyan = require('bunyan');
var log = bunyan.createLogger({name: 'keepass'});
var optional = require('require-optional');
var _ = require('lodash');
var crypto = require('crypto');
var generateKey = function () {
return crypto.randomBytes(256).toString('hex');
};
var readConfig = function () {
var port = process.env.PORT || 8443;
var cryptKey = generateKey();
var jwtSecret = generateKey();
var config = optional('./keepass-node-config', {"port": port});
config = _.extend({
databaseDir: __dirname + '/local/',
publicResourcesDir: __dirname + '/public/',
cryptKey: cryptKey,
jwtSecret: jwtSecret,
jwtUserProperty: 'jwt'
}, config);
return config;
};
var config = readConfig();
var keepassLib = require('./lib');
var express = require('express');
var app = express();
app.use(require("compression")());
if (config.basicAuth && config.basicAuth.enabled) {
app.use(keepassLib.BasicAuth(config.basicAuth));
}
if (config.googleDrive && config.googleDrive.enabled) {
// TODO verify whether this still works
var googleDrive = keepassLib.GoogleDrive('/update', config.googleDrive);
app.use('/update', googleDrive);
}
app.use(keepassLib.Backend(config));
if (config.https && config.https.enabled) {
var https = require('https');
https.createServer(config.https.options, app).listen(config.port);
}
else {
app.listen(config.port);
}
log.info('server is listening on port ' + config.port);
})();