-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
51 lines (41 loc) · 1.07 KB
/
app.js
File metadata and controls
51 lines (41 loc) · 1.07 KB
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
/**
* IdentityChain Agent REST API
* Main
*/
const config = require('./config');
const express = require('express');
// require db at start to establish connection
// and all models so they are available
// through Mongoose.model later on
require('./db');
require('./models');
const lib = require('./lib');
const log = require('./log').log;
const routes = require('./routes/index');
lib.setup(config.LIB_OPTIONS);
const app = express();
app.use('/', routes);
/**
* Initializes pool and db connection
*/
async function initialize() {
try {
await lib.ledger.createConfig();
} catch (err) {
log.warn(err);
}
await lib.ledger.open();
await lib.blobStorage.open();
}
initialize()
.then(() => {
const server = app.listen(config.APP_PORT, config.APP_HOST, async () => {
log.info('IDChain API now up at %s:%s', server.address().address, server.address().port);
log.info('Access APIDocs at /api/docs');
});
})
.catch(err => {
log.error(err);
process.exit(1);
});
module.exports = app;