-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
53 lines (40 loc) · 1.18 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
/**
* IdentityChain Cloud Agent
* Main
*/
require('dotenv').config();
const express = require('express');
const YAML = require('yamljs');
const swaggerUi = require('swagger-ui-express');
const swaggerDoc = YAML.load('./swagger.yaml');
const log = require('./util/log').log;
const pool = require('./lib/pool');
const wallet = require('./lib/wallet');
const middleware = require('./middleware');
const routes = require('./routes');
const app = express();
app.use(middleware.before);
app.use('/ca/api/docs', swaggerUi.serve, swaggerUi.setup(swaggerDoc));
app.use('/ca/api/', routes);
app.use(middleware.after);
const server = app.listen(process.env.IDC_CA_APP_PORT, process.env.IDC_CA_APP_HOST, async () => {
log.info('IDChain Cloud Agent API now up at %s:%s', server.address().address, server.address().port);
log.info('Access APIDocs at /ca/api/docs');
try {
await pool.createConfig();
} catch (err) {
log.warn(err);
}
try {
await pool.openLedger();
} catch (err) {
log.error(err);
process.exit(1);
}
try {
await wallet.createWallet();
} catch (err) {
log.error(err);
}
});
module.exports = app;