-
Notifications
You must be signed in to change notification settings - Fork 28
/
app.js
62 lines (49 loc) · 1.77 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
61
62
const express = require('express');
const bodyParser = require("body-parser");
const cors = require('cors');
const cfg = require('./config');
const logger = cfg.log4js.getLogger('app');
const FabricStarterRuntime = require('./service/context/fabric-starter-runtime');
const NodeComponentsManager = require('./service/nodecomponents/node-components-manager');
const Org = require("./model/Org");
let server;
(async function () {
const app = initAppExpress();
server = startHttpAppServer(app);
initStaticApi(app, server);
const fabricStarterRuntime = new FabricStarterRuntime(app, server)
const nodeComponentsManager = new NodeComponentsManager(fabricStarterRuntime)
initManagementApi(app, server, nodeComponentsManager)
const defaultOrg = Org.fromConfig(cfg);
if (await fabricStarterRuntime.setOrg(defaultOrg)) {
await fabricStarterRuntime.tryInitRuntime(defaultOrg)
}
})()
function startHttpAppServer(app) {
app.disable('etag');
const server = app.listen(process.env.PORT || 3000, () => {
logger.info('started fabric-starter rest server on port', server.address().port);
});
return server;
}
function initAppExpress() {
const app = express();
app.use(bodyParser.json({limit: '100MB', type: 'application/json'}));
app.use(bodyParser.urlencoded({extended: true, limit: '100MB'}));
// allow CORS from all urls
app.use(cors());
app.options('*', cors());
return app;
}
function initStaticApi(app, server) {
require('./api/static-api')(app, server);
}
function initManagementApi(app, server, nodeComponentsManager) {
require('./api/node-components-management-api')(app, server, nodeComponentsManager);
}
function stopServer() {
server && server.close()
}
module.exports = {
stopServer: stopServer
}