-
Notifications
You must be signed in to change notification settings - Fork 42
/
server.js
115 lines (98 loc) · 4.37 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
var config = require('./config');
var http = require('http');
var https = require('https');
var fs = require('fs');
var express = require('express');
var morgan = require('morgan');
var store = require('./lib/store')(config.dbtype);
var hmac = require('./lib/hmac');
var ecdsa = require('./lib/ecdsa')(store);
var api = require('./api');
var guard = require('./guard')(store)
var limiter = guard.resend_email();
var blobIdentity = require('./lib/blobIdentity');
var log = require('./lib/log.js').winston;
var health = require('./health')(store.db)
health.start()
console.log(ecdsa);
api.setStore(store);
hmac.setStore(store);
blobIdentity.setStore(store);
var app = express();
app.use(morgan(':remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"', {stream: log.winstonStream}));
app.use(express.json());
app.use(express.urlencoded());
var cors = require('cors');
app.use(cors());
// JSON handlers
app.post('/v1/user', ecdsa.create, api.blob.create);
app.post('/v1/user/email', limiter.check, ecdsa.middleware, api.user.emailResend);
app.post('/v1/user/:username/rename', ecdsa.middleware, api.user.rename);
app.post('/v1/user/:username/updatekeys', ecdsa.middleware, api.user.updatekeys);
app.get('/v1/user/recov/:username', ecdsa.recover, api.user.recover);//DEPRECIATE THIS
app.get('/v1/user/recover/:username', ecdsa.recover, api.user.recover);
app.post('/v1/user/:username/profile', hmac.middleware, api.user.profile);
app.post('/v1/user/:username/notify_2fa_change', api.user.notify_2fa_change);
app.post('/v1/user/:username/notify_verify_ok', api.user.notify_verify_ok);
app.post('/v1/user/:username/notify_verify_fail', api.user.notify_verify_fail);
app.post('/v1/user/:username/notify_verify_pending', api.user.notify_verify_pending);
app.post('/v1/user/:username/notify_step_null', api.user.notify_step_null);
app.post('/v1/user/:username/notify_step_jumio_id', api.user.notify_step_jumio_id);
app.post('/v1/user/:username/notify_step_jumio_doc', api.user.notify_step_jumio_doc);
app.post('/v1/user/:username/notify_step_jumio_company', api.user.notify_step_jumio_company);
app.post('/v1/user/:username/notify_step_jumio_id2', api.user.notify_step_jumio_id2);
app.post('/v1/user/:username/notify_step_jumio_com_id', api.user.notify_step_jumio_com_id);
app.post('/v1/lookup', api.user.batchlookup)
app.delete('/v1/user/:username', ecdsa.middleware, api.blob.delete);
app.get('/v1/user/:username', api.user.get);
app.get('/v1/user/:username/verify/:token', api.user.verify);
// blob related
app.get('/v1/blob/:blob_id', api.blob.get);
app.post('/v1/blob/patch', hmac.middleware, api.blob.patch);
app.get('/v1/blob/:blob_id/patch/:patch_id', api.blob.getPatch);
app.post('/v1/blob/consolidate', hmac.middleware, api.blob.consolidate);
// old phone validation
app.post('/v1/user/:username/phone', api.user.phoneRequest)
app.post('/v1/user/:username/phone/validate', api.user.phoneValidate)
// 2FA
app.post('/v1/blob/:blob_id/2fa', ecdsa.middleware, api.user.set2fa)
app.get('/v1/blob/:blob_id/2fa', hmac.middleware, api.user.get2fa)
app.get('/v1/blob/:blob_id/2fa/requestToken', api.user.request2faToken)
app.post('/v1/blob/:blob_id/2fa/verifyToken', api.user.verify2faToken)
//signing certificate endpoints
app.get('/v1/oauth2/cert', api.keys.public);
app.get('/v1/oauth2/jwks', api.keys.jwks);
app.get('/v1/authinfo', api.user.authinfo);
app.get('/health', health.status);
app.get('/logs', api.blob.logs);
app.get('/', function (req, res) {
res.send('');
});
try {
var server = config.ssl ? https.createServer({
key: fs.readFileSync(__dirname + '/blobvault.key'),
ca: fs.readFileSync(__dirname + '/intermediate.crt'),
cert: fs.readFileSync(__dirname + '/blobvault.crt')
}, app) : http.createServer(app);
var port = config.port || (config.ssl ? 443 : 8080);
server.listen(port, config.host);
log.info("Blobvault listening on port "+port);
} catch (e) {
log.info("Could not launch SSL server: " + (e.stack ? e.stack : e.toString()));
}
process.on('SIGTERM',function() {
log.warn("caught sigterm");
process.exit();
});
process.on('SIGINT',function() {
log.warn("caught sigint");
process.exit();
});
process.on('exit',function() {
log.info("Shutting down.");
// emailCampaign.stop();
if (store.db && store.db.client) {
store.db.client.pool.destroy();
}
log.info("Done");
});