-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (34 loc) · 1.02 KB
/
index.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
'use strict';
const http = require('http');
const express = require('express');
const { BLUE, RESET, PORT } = require('./constants');
const { createCryptoMaterial } = require('./dlt/fabric-ca');
const {
GetAllAssets,
ReadAsset,
CreateAsset,
TransferAsset,
UpdateAsset,
DeleteAsset,
} = require('./handlers');
async function main() {
console.log(`${BLUE} ************ START ************ ${RESET}`);
const app = express();
app.use(express.json());
app.get('/assets', GetAllAssets);
app.get('/assets/:id', ReadAsset);
app.post('/assets', CreateAsset);
app.put('/assets', UpdateAsset);
app.post('/assets/transfer', TransferAsset);
app.delete('/assets/:id', DeleteAsset);
const server = http.createServer(app);
server.listen(PORT, async function () {
// Need to run this only once
await createCryptoMaterial();
console.log(
`${BLUE} --------------------- app up on port:${PORT} ---------------------${RESET}`
);
});
console.log(`${BLUE} ************ END ************ ${RESET}`);
}
main();